Issue #7316: the acquire() method of lock objects in the :mod:`threading`
module now takes an optional timeout argument in seconds. Timeout support
relies on the system threading library, so as to avoid a semi-busy wait
loop.
diff --git a/Lib/_dummy_thread.py b/Lib/_dummy_thread.py
index 7aa6579..e10bae8 100644
--- a/Lib/_dummy_thread.py
+++ b/Lib/_dummy_thread.py
@@ -17,6 +17,10 @@
'interrupt_main', 'LockType']
import traceback as _traceback
+import time
+
+# A dummy value
+TIMEOUT_MAX = 2**31
class error(Exception):
"""Dummy implementation of _thread.error."""
@@ -92,7 +96,7 @@
def __init__(self):
self.locked_status = False
- def acquire(self, waitflag=None):
+ def acquire(self, waitflag=None, timeout=-1):
"""Dummy implementation of acquire().
For blocking calls, self.locked_status is automatically set to
@@ -111,6 +115,8 @@
self.locked_status = True
return True
else:
+ if timeout > 0:
+ time.sleep(timeout)
return False
__enter__ = acquire