From e10ca3a0fe10d825689179e9958c70aef01f4230 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 27 Dec 2016 14:19:20 +0100 Subject: Issue #28427: old keys should not remove new values from WeakValueDictionary when collecting from another thread. --- Lib/test/test_weakref.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Lib/test/test_weakref.py') diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 28a1cc2bfa..1aa354019d 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -1673,6 +1673,18 @@ class MappingTestCase(TestBase): x = d.pop(10, 10) self.assertIsNot(x, None) # we never put None in there! + def test_threaded_weak_valued_consistency(self): + # Issue #28427: old keys should not remove new values from + # WeakValueDictionary when collecting from another thread. + d = weakref.WeakValueDictionary() + with collect_in_thread(): + for i in range(200000): + o = RefCycle() + d[10] = o + # o is still alive, so the dict can't be empty + self.assertEqual(len(d), 1) + o = None # lose ref + from test import mapping_tests -- cgit v1.2.1