Message145521
| Author |
rhettinger |
| Recipients |
ezio.melotti, rhettinger |
| Date |
2011年10月14日.14:31:31 |
| SpamBayes Score |
0.00048330054 |
| Marked as misclassified |
No |
| Message-id |
<1318602692.63.0.65428014746.issue13177@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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 |
|
History
|
|---|
| 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 |
|