[issue33047] "RuntimeError: dictionary changed size during iteration" using trace.py module

Adrien report at bugs.python.org
Sat Mar 17 09:00:56 EDT 2018


Adrien <delgan.py at gmail.com> added the comment:

Thanks for your attention to this issue.

I am not surprised that you was not able to reproduce it as it seems deeply related to multiprocessing and threads. 

I tested it on 3 others completely different computers, and I was able to reproduce the error for 2 of them which were running Ubuntu 16.04 and  Windows 10. I made a totally fresh install of Python 3.6.4, the Windows machine never had Python installed before. 
The only common point between computers where the error occurs compared to the third one, whether running Windows or Linux, is that they have a fairly old or weak hardware, and therefore are slower.

Fortunately, the error was systematic on my machine. So I was able to study the trace.py code to try to isolate the problem. Piece by piece, I simplified trace.py to get a small snippet that reproduces the bug (I joined the file to this message).
Sometimes, there is also a "BrokenPipeError" which pop-out. I do not know if this is related.

The error seems to come from the fact that "counts" start to be iterated while compiled code execution is not fully terminated, and so "localtrace_count" may add another item to the dict. Move the "time.sleep()" before the loop and the error should gone. This is most likely related to the internal thread used by Queue as using a SimpleQueue doesn't raise an exception.

As I do not have access for now to a computer where the error does not occur, I can not continue my investigations. However I hope that I give a little more information so that you maybe succeed to reproduce it.

----------
Added file: https://bugs.python.org/file47493/minitrace.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33047>
_______________________________________


More information about the Python-bugs-list mailing list