mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Handle a possible race condition
This commit is contained in:
parent
ca9bfe17be
commit
34d94a2101
1 changed files with 6 additions and 0 deletions
|
@ -241,6 +241,12 @@ def lru_cache(maxsize=100, typed=False):
|
|||
return result
|
||||
result = user_function(*args, **kwds)
|
||||
with lock:
|
||||
if key in cache:
|
||||
# getting here means that this same key was added to the
|
||||
# cache while the lock was released. since the link
|
||||
# update is already done, we need only return the
|
||||
# computed result and update the count of misses.
|
||||
pass
|
||||
if currsize < maxsize:
|
||||
# put result in a new link at the front of the queue
|
||||
last = root[PREV]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue