diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-14 15:44:10 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-14 15:44:10 (GMT) |
commit | 7c3e5773954009d65520eb063621cf7724da88e3 (patch) | |
tree | 12c9dc646c8a80043616bf4fa54e3dedb84df9ca /Lib/_dummy_thread.py | |
parent | e53de3dc4a9021b5edabd44fd495df7770b6249c (diff) | |
download | cpython-7c3e5773954009d65520eb063621cf7724da88e3.zip cpython-7c3e5773954009d65520eb063621cf7724da88e3.tar.gz cpython-7c3e5773954009d65520eb063621cf7724da88e3.tar.bz2 |
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.
Diffstat (limited to 'Lib/_dummy_thread.py')
-rw-r--r-- | Lib/_dummy_thread.py | 8 |
1 files changed, 7 insertions, 1 deletions
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 @@ __all__ = ['error', 'start_new_thread', 'exit', 'get_ident', 'allocate_lock', '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 @@ class LockType(object): 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 @@ class LockType(object): self.locked_status = True return True else: + if timeout > 0: + time.sleep(timeout) return False __enter__ = acquire |