diff rhodecode/lib/compat.py @ 2730:7949bc80b3b1 beta

more py25 compat fixes
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 22 Aug 2012 13:30:52 +0200
parents e9e7c40b4f1a
children 3c0ae44557c4
line wrap: on
line diff
--- a/rhodecode/lib/compat.py	Wed Aug 22 12:09:49 2012 +0200
+++ b/rhodecode/lib/compat.py	Wed Aug 22 13:30:52 2012 +0200
@@ -530,3 +530,56 @@
             memo[id(self)] = result
             result.__init__(deepcopy(tuple(self), memo))
             return result
+
+
+#==============================================================================
+# threading.Event
+#==============================================================================
+
+if __py_version__ >= (2, 6):
+    from threading import Event
+else:
+    from threading import _Verbose, Condition, Lock
+
+    def Event(*args, **kwargs):
+        return _Event(*args, **kwargs)
+
+    class _Event(_Verbose):
+
+        # After Tim Peters' event class (without is_posted())
+
+        def __init__(self, verbose=None):
+            _Verbose.__init__(self, verbose)
+            self.__cond = Condition(Lock())
+            self.__flag = False
+
+        def isSet(self):
+            return self.__flag
+
+        is_set = isSet
+
+        def set(self):
+            self.__cond.acquire()
+            try:
+                self.__flag = True
+                self.__cond.notify_all()
+            finally:
+                self.__cond.release()
+
+        def clear(self):
+            self.__cond.acquire()
+            try:
+                self.__flag = False
+            finally:
+                self.__cond.release()
+
+        def wait(self, timeout=None):
+            self.__cond.acquire()
+            try:
+                if not self.__flag:
+                    self.__cond.wait(timeout)
+            finally:
+                self.__cond.release()
+
+
+