Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34d94a2

Browse files
committed
Handle a possible race condition
1 parent ca9bfe1 commit 34d94a2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Lib/functools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ def wrapper(*args, **kwds):
241241
return result
242242
result = user_function(*args, **kwds)
243243
with lock:
244+
if key in cache:
245+
# getting here means that this same key was added to the
246+
# cache while the lock was released. since the link
247+
# update is already done, we need only return the
248+
# computed result and update the count of misses.
249+
pass
244250
if currsize < maxsize:
245251
# put result in a new link at the front of the queue
246252
last = root[PREV]

0 commit comments

Comments
 (0)