close

ImageImage

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author arigo
Recipients arigo
Date 2016-12-06.11:58:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1481025524.61.0.807686786444.issue28884@psf.upfronthosting.co.za>
In-reply-to
Content
(B8) also discussed in connection with https://bugs.python.org/issue28427

  weak dicts (both kinds) and weak sets have an implementation of
  __len__ which doesn't give the "expected" result on PyPy, and in some
  cases on CPython too.  I'm not sure what is expected and what is not.
  Here is an example on CPython 3.5.2+ (using a thread to run the weakref
  callbacks only, not to explicitly inspect or modify 'd')::

    import weakref, _thread
    from queue import Queue

    queue = Queue()
    def subthread(queue):
        while True:
            queue.get()
    _thread.start_new_thread(subthread, (queue,))

    class X:
        pass
    d = weakref.WeakValueDictionary()
    while True:
        x = X()
        d[52] = x
        queue.put(x)
        del x
        while list(d) != []:
            pass
        assert len(d) == 0  # we've checked that list(d)==[], but this may fail

  On CPython I've seen the assert fail only after editing the function
  WeakValueDictionary.__init__.remove() to add ``time.sleep(0.01)`` as
  the first line.  Otherwise I guess the timings happen to make that test
  pass.
History
Date User Action Args
2016-12-06 11:58:44arigosetrecipients: + arigo
2016-12-06 11:58:44arigosetmessageid: <1481025524.61.0.807686786444.issue28884@psf.upfronthosting.co.za>
2016-12-06 11:58:44arigolinkissue28884 messages
2016-12-06 11:58:44arigocreate