[Python-Dev] Weak Dictionary Iteration Behavior in Python 3 (original) (raw)
Armin Ronacher armin.ronacher at active-4.com
Sun Sep 14 11:35:52 CEST 2008
- Previous message: [Python-Dev] Weak Dictionary Iteration Behavior in Python 3
- Next message: [Python-Dev] Weak Dictionary Iteration Behavior in Python 3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
Josiah Carlson <josiah.carlson gmail.com> writes:
i = list(d.keys()) Obviously that doesn't solve the problem. list() consumes the generator one after another, objects can still die when the list is created. Imagine the following example which uses threads::
from time import sleep
from weakref import WeakKeyDictionary
from threading import Thread
class Foo(object):
pass
d = WeakKeyDictionary()
l = []
for x in range(100000):
obj = Foo()
d[obj] = None
l.append(obj)
del obj
def iterater():
for item in list(d.keys()):
pass
Thread(target=iterater).start()
while True:
del l[0]
Regards, Armin
- Previous message: [Python-Dev] Weak Dictionary Iteration Behavior in Python 3
- Next message: [Python-Dev] Weak Dictionary Iteration Behavior in Python 3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]