[issue35615] "RuntimeError: Dictionary changed size during iteration" when copying a WeakValueDictionary

Daniel Romberg report at bugs.python.org
Mon Jan 25 10:44:14 EST 2021


Daniel Romberg <daniel at romberg.io> added the comment:

I think this issue needs to be reopened. The problem has not been solved completely. We experience a lot fewer crashes in weakref than before this fix, however, there are recursive situations in which copy() is invoked while iterating the WeakValueDictionary (e.g., in our case it is a signal/slot implementation where the slots are stored in a WeakValueDictionary). _commit_removals(), which is called at the beginning of the copy operation, might change the dictionary if there are items that are to be removed. If there is an ongoing iteration, the corresponding RuntimeError is raised.

I haven't thought that through entirely, but I wonder whether the copy (and also deepcopy) operation could just blindly copy everything without "committing removals". After the copy, both instances would do their _commit_removals on their own upon access.

----------
nosy: +djromberg

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


More information about the Python-bugs-list mailing list