Commit 34d94a21 authored by Raymond Hettinger's avatar Raymond Hettinger

Handle a possible race condition

parent ca9bfe17
......@@ -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]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment