Explorar o código

Replaces lock.aquires/try/finally/release by a with statement.

rnoel %!s(int64=13) %!d(string=hai) anos
pai
achega
1a59e5ffc8
Modificáronse 1 ficheiros con 3 adicións e 9 borrados
  1. 3 9
      celery/datastructures.py

+ 3 - 9
celery/datastructures.py

@@ -9,6 +9,7 @@ Custom data structures.
 
 """
 from __future__ import absolute_import
+from __future__ import with_statement
 
 import time
 import traceback
@@ -303,21 +304,14 @@ class LocalCache(OrderedDict):
         self.lock = Lock()
 
     def __setitem__(self, key, value):
-        self.lock.acquire()   
-        try:
+        with self.lock:
             while len(self) >= self.limit:
                 self.popitem(last=False)
             super(LocalCache, self).__setitem__(key, value)
-        finally:
-          self.lock.release()
 
     def pop(self, key, *args):
-        self.lock.acquire()   
-        try:
+        with self.lock:
             self.pop(key, *args)
-        finally:
-          self.lock.release()
-
 
 
 class TokenBucket(object):