mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #28991: Fix obscure reentrancy bug in functools.lru_cache().
This commit is contained in:
parent
ac13beeef5
commit
af56e0e70f
3 changed files with 20 additions and 2 deletions
|
@ -516,14 +516,16 @@ def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
|
|||
last = root[PREV]
|
||||
link = [last, root, key, result]
|
||||
last[NEXT] = root[PREV] = cache[key] = link
|
||||
full = (len(cache) >= maxsize)
|
||||
# Use the __len__() method instead of the len() function
|
||||
# which could potentially be wrapped in an lru_cache itself.
|
||||
full = (cache.__len__() >= maxsize)
|
||||
misses += 1
|
||||
return result
|
||||
|
||||
def cache_info():
|
||||
"""Report cache statistics"""
|
||||
with lock:
|
||||
return _CacheInfo(hits, misses, maxsize, len(cache))
|
||||
return _CacheInfo(hits, misses, maxsize, cache.__len__())
|
||||
|
||||
def cache_clear():
|
||||
"""Clear the cache and cache statistics"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue