diff options
author | Raymond Hettinger <python@rcn.com> | 2012-04-30 21:14:28 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2012-04-30 21:14:28 (GMT) |
commit | 34d94a21018e8172f4e57a96fb537427f9dbb251 (patch) | |
tree | 5a78b98c1f30fe5518aef10639d02c51b65c88fe /Lib/functools.py | |
parent | ca9bfe17be987163c4530a7853617cc028854ffb (diff) | |
download | cpython-34d94a21018e8172f4e57a96fb537427f9dbb251.zip cpython-34d94a21018e8172f4e57a96fb537427f9dbb251.tar.gz cpython-34d94a21018e8172f4e57a96fb537427f9dbb251.tar.bz2 |
Handle a possible race condition
Diffstat (limited to 'Lib/functools.py')
-rw-r--r-- | Lib/functools.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/functools.py b/Lib/functools.py index e4458f4..8206c4a 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -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] |