cpython: ac2715d04119 (original) (raw)

Mercurial > cpython

changeset 105740:ac2715d04119

Issue #19542: Fix bugs in WeakValueDictionary.setdefault() and WeakValueDictionary.pop() when a GC collection happens in another thread. Original patch and report by Armin Rigo. [#19542]

Antoine Pitrou solipsis@pitrou.net
date Mon, 19 Dec 2016 10:59:15 +0100
parents 5c5cf7687dc1(current diff)f3706a9430da(diff)
children 9568343fde42
files Misc/NEWS
diffstat 3 files changed, 53 insertions(+), 5 deletions(-)[+] [-] Lib/test/test_weakref.py 41 Lib/weakref.py 13 Misc/NEWS 4

line wrap: on

line diff

--- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -6,6 +6,7 @@ import weakref import operator import contextlib import copy +import time from test import support from test.support import script_helper @@ -72,6 +73,29 @@ class TestBase(unittest.TestCase): self.cbcalled += 1 +@contextlib.contextmanager +def collect_in_thread(period=0.0001):

+

+

+ + class ReferencesTestCase(TestBase): def test_basic_ref(self): @@ -1636,6 +1660,23 @@ class MappingTestCase(TestBase): dict = weakref.WeakKeyDictionary() self.assertRegex(repr(dict), '<WeakKeyDictionary at 0x.*>')

+

+ + from test import mapping_tests class WeakValueDictionaryTestCase(mapping_tests.BasicTestMappingProtocol):

--- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -239,24 +239,27 @@ class WeakValueDictionary(collections.Mu try: o = self.data.pop(key)() except KeyError:

def setdefault(self, key, default=None): try:

def update(*args, **kwargs): if not args:

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,10 @@ Core and Builtins Library ------- +- Issue #19542: Fix bugs in WeakValueDictionary.setdefault() and