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 colesbury
Recipients colesbury
Date 2021-11-15.19:02:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1637002958.39.0.243945007085.issue45809@roundup.psfhosted.org>
In-reply-to
Content
The issue described issue7105 (and maybe issue7060) still exists due to a race condition in WeakKeyDictionary. This shows up as test failure that looks like:

  test test_weakref failed -- Traceback (most recent call last):
    File "Lib/test/test_weakref.py", line 1960, in test_threaded_weak_value_dict_deepcopy
      self.check_threaded_weak_dict_copy(weakref.WeakValueDictionary, True)
    File "Lib/test/test_weakref.py", line 1940, in check_threaded_weak_dict_copy
      raise exc[0]
    File "Lib/test/test_weakref.py", line 1897, in dict_copy
      _ = copy.deepcopy(d)
    File "Lib/copy.py", line 153, in deepcopy
      y = copier(memo)
    File "Lib/weakref.py", line 189, in __deepcopy__
      for key, wr in self.data.items():
  RuntimeError: dictionary changed size during iteration

The cause is that the check of "self._iterating" and the call to "_atomic_removal" are not performed atomically together. By the time _atomic_removal() is called, an iteration might have already started.

https://github.com/python/cpython/blob/ec382fac0db6d9159c2d3496a70b7a605545957e/Lib/weakref.py#L109-L114
History
Date User Action Args
2021-11-15 19:02:38colesburysetrecipients: + colesbury
2021-11-15 19:02:38colesburysetmessageid: <1637002958.39.0.243945007085.issue45809@roundup.psfhosted.org>
2021-11-15 19:02:38colesburylinkissue45809 messages
2021-11-15 19:02:38colesburycreate