[Python-bugs-list] [ python-Bugs-742860 ] WeakKeyDictionary __delitem__ uses iterkeys

SourceForge.net noreply@sourceforge.net
Sat, 24 May 2003 13:50:09 -0700


Bugs item #742860, was opened at 2003-05-24 16:24
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=742860&group_id=5470

Category: Python Library
Group: Python 2.2.2
Status: Open
Resolution: None
>Priority: 6
Submitted By: Mike C. Fletcher (mcfletch)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: WeakKeyDictionary __delitem__ uses iterkeys

Initial Comment:
iterkeys will raise a RuntimeError if the size of the
dictionary changes during iteration.  Deleting items
from the dictionary may cause cascade deletions which
will change the dictionary size.

Possible solutions:
    Use keys instead of iterkeys: line 155 of weakref.py:
        for ref in self.data.keys():

    Document the possibility that __delitem__ will
raise RuntimeErrors (not a preferable solution).

Note that there is also a potential race condition in
the __delitem__ method, where the key is del'd from the
data dictionary without a try: except: to catch cases
where the key is deleted between the time the key is
retrieved and the time the deletion occurs (which is
more likely if keys is used, but could still happen
with iterkeys).

Same problem is seen in both 2.2.2 and 2.2.3

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2003-05-24 16:50

Message:
Logged In: YES 
user_id=31435

Assigned to Fred (the original author, IIRC), and boosted 
priority a notch.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=742860&group_id=5470