cpython: f3706a9430da (original) (raw)

Mercurial > cpython

changeset 105739:f3706a9430da 3.6

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:58:14 +0100
parents 781c56168484(current diff)5a542a2bca08(diff)
children ac2715d04119 da958d01755a
files Lib/test/test_weakref.py 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 @@ -38,6 +38,10 @@ Core and Builtins Library ------- +- Issue #19542: Fix bugs in WeakValueDictionary.setdefault() and