summaryrefslogtreecommitdiffstats
path: root/Lib/weakref.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2016-12-19 09:56:40 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2016-12-19 09:56:40 (GMT)
commitc1ee488962f0a20c2814b14a4c29d6082dd38add (patch)
tree08884079e3c2da9de5e337ae9d78b6410fa683ef /Lib/weakref.py
parentca3263c50c3b3a3719d2ec3ee7b30b8c669dcb19 (diff)
downloadcpython-c1ee488962f0a20c2814b14a4c29d6082dd38add.zip
cpython-c1ee488962f0a20c2814b14a4c29d6082dd38add.tar.gz
cpython-c1ee488962f0a20c2814b14a4c29d6082dd38add.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.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py
index 2968fb9..9f8ef3e 100644
--- a/Lib/weakref.py
+++ b/Lib/weakref.py
@@ -239,24 +239,27 @@ class WeakValueDictionary(collections.MutableMapping):
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: