Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

I afraid that this is a part of the larger issue (see also issue31165). Seems 
the cause is that the GIL can be released when allocate or reallocate the 
memory. Does your project use some memory managing hooks?

Using sys.modules.copy().items() can help a lot, because you allocate memory 
for new dict only once. In case of list(sys.modules.items()) you allocate 
memory for every key-value pair, and may allocate memory several times to 
resize a list.

This reduces the probability of occurring the problem in many times, but not to 
zero. There is still a chance that the size of the original dict increase when 
you allocate a memory for a new dict, so copying the data to a new dict can 
fail or even crash or spoil the memory.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40327>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to