homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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:32rhettingersetrecipients: + rhettinger, ezio.melotti
2011年10月14日 14:31:32rhettingersetmessageid: <1318602692.63.0.65428014746.issue13177@psf.upfronthosting.co.za>
2011年10月14日 14:31:32rhettingerlinkissue13177 messages
2011年10月14日 14:31:31rhettingercreate

AltStyle によって変換されたページ (->オリジナル) /