Explorar o código

memoize: LRUCache already thread-safe.

Ask Solem %!s(int64=9) %!d(string=hai) anos
pai
achega
f80dca3982
Modificáronse 1 ficheiros con 2 adicións e 5 borrados
  1. 2 5
      celery/utils/functional.py

+ 2 - 5
celery/utils/functional.py

@@ -150,7 +150,6 @@ class LRUCache(UserDict):
 def memoize(maxsize=None, keyfun=None, Cache=LRUCache):
 
     def _memoize(fun):
-        mutex = threading.Lock()
         cache = Cache(limit=maxsize)
 
         @wraps(fun)
@@ -160,13 +159,11 @@ def memoize(maxsize=None, keyfun=None, Cache=LRUCache):
             else:
                 key = args + (KEYWORD_MARK,) + tuple(sorted(kwargs.items()))
             try:
-                with mutex:
-                    value = cache[key]
+                value = cache[key]
             except KeyError:
                 value = fun(*args, **kwargs)
                 _M.misses += 1
-                with mutex:
-                    cache[key] = value
+                cache[key] = value
             else:
                 _M.hits += 1
             return value