Skip to content

Commit a7f206c

Browse files
committed
Fix race condition in cached_method
Multiple weakrefs can be created when there are concurrent writes to a "new cache". When they finalize, their attempts to clear the dict should be kept safe by using a pop() default.
1 parent 8086aa5 commit a7f206c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Lib/functools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ def register(self):
11341134

11351135
def _cached_method_weakref_callback(cache_dict, id_key):
11361136
def callback(ref):
1137-
cache_dict.pop(id_key)
1137+
cache_dict.pop(id_key, None)
11381138
return callback
11391139

11401140

0 commit comments

Comments
 (0)