Raymond Hettinger <raymond.hettin...@gmail.com> added the comment: 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 ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13177> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com