Blame 00181-allow-arbitrary-timeout-in-condition-wait.patch

a31104c
diff --git a/Lib/threading.py b/Lib/threading.py
a31104c
index cb49c4a..c9795a5 100644
a31104c
--- a/Lib/threading.py
a31104c
+++ b/Lib/threading.py
a31104c
@@ -305,7 +305,7 @@ class _Condition(_Verbose):
a31104c
         else:
a31104c
             return True
a31104c
 
a31104c
-    def wait(self, timeout=None):
a31104c
+    def wait(self, timeout=None, balancing=True):
a31104c
         """Wait until notified or until a timeout occurs.
a31104c
 
a31104c
         If the calling thread has not acquired the lock when this method is
a31104c
@@ -354,7 +354,10 @@ class _Condition(_Verbose):
a31104c
                     remaining = endtime - _time()
a31104c
                     if remaining <= 0:
a31104c
                         break
a31104c
-                    delay = min(delay * 2, remaining, .05)
a31104c
+                    if balancing:
a31104c
+                        delay = min(delay * 2, remaining, 0.05)
a31104c
+                    else:
a31104c
+                        delay = remaining
a31104c
                     _sleep(delay)
a31104c
                 if not gotit:
a31104c
                     if __debug__:
a31104c
@@ -599,7 +602,7 @@ class _Event(_Verbose):
Robert Kuska 7af76a5
         with self.__cond:
Robert Kuska 7af76a5
             self.__flag = False
a31104c
 
a31104c
-    def wait(self, timeout=None):
a31104c
+    def wait(self, timeout=None, balancing=True):
a31104c
         """Block until the internal flag is true.
a31104c
 
a31104c
         If the internal flag is true on entry, return immediately. Otherwise,
a31104c
@@ -617,7 +620,7 @@ class _Event(_Verbose):
Robert Kuska 7af76a5
         """
Robert Kuska 7af76a5
         with self.__cond:
a31104c
             if not self.__flag:
a31104c
-                self.__cond.wait(timeout)
a31104c
+                self.__cond.wait(timeout, balancing)
a31104c
             return self.__flag
Robert Kuska 7af76a5
Robert Kuska 7af76a5
 # Helper to generate new thread names
a31104c
@@ -908,7 +911,7 @@ class Thread(_Verbose):
a31104c
             if 'dummy_threading' not in _sys.modules:
a31104c
                 raise
a31104c
 
a31104c
-    def join(self, timeout=None):
a31104c
+    def join(self, timeout=None, balancing=True):
a31104c
         """Wait until the thread terminates.
a31104c
 
a31104c
         This blocks the calling thread until the thread whose join() method is
a31104c
@@ -957,7 +960,7 @@ class Thread(_Verbose):
a31104c
                         if __debug__:
a31104c
                             self._note("%s.join(): timed out", self)
a31104c
                         break
a31104c
-                    self.__block.wait(delay)
a31104c
+                    self.__block.wait(delay, balancing)
a31104c
                 else:
a31104c
                     if __debug__:
a31104c
                         self._note("%s.join(): thread stopped", self)
a31104c
@@ -1143,7 +1146,7 @@ class _DummyThread(Thread):
a31104c
     def _set_daemon(self):
a31104c
         return True
a31104c
 
a31104c
-    def join(self, timeout=None):
a31104c
+    def join(self, timeout=None, balancing=True):
a31104c
         assert False, "cannot join a dummy thread"
a31104c
 
a31104c