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