A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-September/082380.html below:

[Python-Dev] Weak Dictionary Iteration Behavior in Python 3

[Python-Dev] Weak Dictionary Iteration Behavior in Python 3 [Python-Dev] Weak Dictionary Iteration Behavior in Python 3Armin Ronacher armin.ronacher at active-4.com
Sun Sep 14 11:35:52 CEST 2008
Hi,

Josiah Carlson <josiah.carlson <at> 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

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4