diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2016-12-19 10:12:58 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2016-12-19 10:12:58 (GMT) |
| commit | 805f283aa311043a498fecc29cf7bc13e4311fd6 (patch) | |
| tree | 69429d7b935fd7f4d1ea2fb039826ecbdbbfb9dd /Lib/weakref.py | |
| parent | 88e420645612cbec172820c2c80a3f1fe68312c7 (diff) | |
| download | cpython-805f283aa311043a498fecc29cf7bc13e4311fd6.zip cpython-805f283aa311043a498fecc29cf7bc13e4311fd6.tar.gz cpython-805f283aa311043a498fecc29cf7bc13e4311fd6.tar.bz2 | |
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.
Diffstat (limited to 'Lib/weakref.py')
| -rw-r--r-- | Lib/weakref.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py index ca37f87..def955f 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -202,24 +202,27 @@ class WeakValueDictionary(UserDict.UserDict): try: o = self.data.pop(key)() except KeyError: + o = None + if o is None: if args: return args[0] - raise - if o is None: - raise KeyError, key + else: + raise KeyError, key else: return o def setdefault(self, key, default=None): try: - wr = self.data[key] + o = self.data[key]() except KeyError: + o = None + if o is None: if self._pending_removals: self._commit_removals() self.data[key] = KeyedRef(default, self._remove, key) return default else: - return wr() + return o def update(*args, **kwargs): if not args: |
