classification
Title: weak dict iterators are fragile because of unpredictable GC runs
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.2, Python 3.1
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, jon, pitrou (3)
Priority: normal Keywords patch

Created on 2009-10-11 17:29 by pitrou, last changed 2009-11-13 17:39 by pitrou.

Files
File name Uploaded Description Edit Remove
weakiter3.patch pitrou, 2009-10-13 17:24
Messages (4)
msg93863 - (view) Author: Antoine Pitrou (pitrou) Date: 2009-10-11 17:29
As mentioned in issue7060, weak dict iterators are easily broken by
cyclic garbage collection changing the size of the underlying dict storage:

  File "/home/rdmurray/python/py3k/Lib/weakref.py", line 121, in items
    for wr in self.data.values():
RuntimeError: dictionary changed size during iteration

One possible solution is to delay all removals until all iterators are
done. Here is a context manager-based solution.
msg93865 - (view) Author: Guido van Rossum (gvanrossum) Date: 2009-10-11 17:57
> delay all removals until all iterators are done

+1
msg93912 - (view) Author: Antoine Pitrou (pitrou) Date: 2009-10-12 23:50
This new patch makes it possible to mutate the dict without messing with
the delayed removal when an iterator exists.
msg93934 - (view) Author: Antoine Pitrou (pitrou) Date: 2009-10-13 17:24
It occurs weaksets have the same problem, here is a new patch fixing
them as well.
History
Date User Action Args
2009-11-13 17:39:30pitrousetfiles: - weakiter2.patch
2009-11-13 17:39:28pitrousetfiles: - weakiter.patch
2009-10-24 12:55:46pitroulinkissue3578 superseder
2009-10-13 17:24:59pitrousetfiles: + weakiter3.patch

messages: + msg93934
2009-10-12 23:51:00pitrousetfiles: + weakiter2.patch

messages: + msg93912
2009-10-11 17:57:27gvanrossumsetnosy: + gvanrossum
messages: + msg93865
2009-10-11 17:36:34jonsetnosy: + jon
2009-10-11 17:29:50pitroulinkissue7060 dependencies
2009-10-11 17:29:21pitroucreate