Message145521
One possibility is to move the call to user_function() outside of the KeyError exception handler so that user exceptions won't be chained:
def wrapper(*args, **kwds):
nonlocal hits, misses
key = args
if kwds:
key += kwd_mark + tuple(sorted(kwds.items()))
try:
with lock:
result = cache[key]
cache_renew(key) # record recent use of this key
hits += 1
return result
except KeyError:
pass
result = user_function(*args, **kwds)
with lock:
cache[key] = result # record recent use of this key
misses += 1
if len(cache) > maxsize:
cache_popitem(0) # purge least recently used cache entry
return result |
|
Date |
User |
Action |
Args |
2011-10-14 14:31:32 | rhettinger | set | recipients:
+ rhettinger, ezio.melotti |
2011-10-14 14:31:32 | rhettinger | set | messageid: <1318602692.63.0.65428014746.issue13177@psf.upfronthosting.co.za> |
2011-10-14 14:31:32 | rhettinger | link | issue13177 messages |
2011-10-14 14:31:31 | rhettinger | create | |
|