Ask Solem 15 роки тому
батько
коміт
a3fa7a68e6
1 змінених файлів з 10 додано та 11 видалено
  1. 10 11
      celery/datastructures.py

+ 10 - 11
celery/datastructures.py

@@ -78,15 +78,15 @@ def consume_queue(queue):
     while True:
     while True:
         try:
         try:
             yield queue.get_nowait()
             yield queue.get_nowait()
-        except QueueEmpty, exc:
-            raise StopIteration()
+        except QueueEmpty:
+            break
 
 
 
 
 class SharedCounter(object):
 class SharedCounter(object):
     """An integer that can be updated by several threads at once.
     """An integer that can be updated by several threads at once.
 
 
     Please note that the final value is not synchronized, this means
     Please note that the final value is not synchronized, this means
-    that you should not update the value on a previous value, the only
+    that you should not update the value by using a previous value, the only
     reliable operations are increment and decrement.
     reliable operations are increment and decrement.
 
 
     Example
     Example
@@ -111,13 +111,13 @@ class SharedCounter(object):
         self._value = initial_value
         self._value = initial_value
         self._modify_queue = Queue()
         self._modify_queue = Queue()
 
 
-    def increment(self):
-        """Increment the value by one."""
-        self += 1
+    def increment(self, n=1):
+        """Increment value."""
+        self += n
 
 
-    def decrement(self):
-        """Decrement the value by one."""
-        self -= 1
+    def decrement(self, n=1):
+        """Decrement value."""
+        self -= n
         
         
     def _update_value(self):
     def _update_value(self):
         self._value += sum(consume_queue(self._modify_queue))
         self._value += sum(consume_queue(self._modify_queue))
@@ -135,8 +135,7 @@ class SharedCounter(object):
 
 
     def __int__(self):
     def __int__(self):
         """``int(self) -> int``"""
         """``int(self) -> int``"""
-        self._update_value()
-        return self._value
+        return self._update_value()
 
 
     def __repr__(self):
     def __repr__(self):
         return "<SharedCounter: int(%s)>" % str(int(self))
         return "<SharedCounter: int(%s)>" % str(int(self))