From: Raymond Hettinger Date: Fri, 1 Mar 2013 11:48:30 +0000 (-0800) Subject: Merge X-Git-Tag: v3.4.0a1~1298 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dacb6858e88b6c4cb4659400e73b81e88864a7fa;p=python Merge --- dacb6858e88b6c4cb4659400e73b81e88864a7fa diff --cc Lib/functools.py index 2647f2da79,71022e53c8..c71d71420b --- a/Lib/functools.py +++ b/Lib/functools.py @@@ -11,15 -11,12 +11,15 @@@ __all__ = ['update_wrapper', 'wraps', 'WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES', 'total_ordering', 'cmp_to_key', 'lru_cache', 'reduce', 'partial'] -from _functools import partial, reduce +try: + from _functools import reduce +except ImportError: + pass from collections import namedtuple try: - from _thread import allocate_lock as Lock + from _thread import RLock except: - from _dummy_thread import allocate_lock as Lock + from dummy_threading import RLock ################################################################################ @@@ -228,11 -202,12 +228,11 @@@ def lru_cache(maxsize=128, typed=False) PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields def decorating_function(user_function): - cache = {} - hits = misses = currsize = 0 + hits = misses = 0 full = False cache_get = cache.get # bound method to lookup a key or return None - lock = Lock() # because linkedlist updates aren't threadsafe + lock = RLock() # because linkedlist updates aren't threadsafe root = [] # root of the circular doubly linked list root[:] = [root, root, None, None] # initialize by pointing to self