summaryrefslogtreecommitdiffstats
path: root/Doc/library/threading.rst
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-14 15:44:10 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-14 15:44:10 (GMT)
commit7c3e5773954009d65520eb063621cf7724da88e3 (patch)
tree12c9dc646c8a80043616bf4fa54e3dedb84df9ca /Doc/library/threading.rst
parente53de3dc4a9021b5edabd44fd495df7770b6249c (diff)
downloadcpython-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 'Doc/library/threading.rst')
-rw-r--r--Doc/library/threading.rst28
1 files changed, 26 insertions, 2 deletions
diff --git a/Doc/library/threading.rst b/Doc/library/threading.rst
index f642111..1f2b763 100644
--- a/Doc/library/threading.rst
+++ b/Doc/library/threading.rst
@@ -155,6 +155,16 @@ This module defines the following functions and objects:
Availability: Windows, systems with POSIX threads.
+This module also defines the following constant:
+
+.. data:: TIMEOUT_MAX
+
+ The maximum value allowed for the *timeout* parameter of blocking functions
+ (:meth:`Lock.acquire`, :meth:`RLock.acquire`, :meth:`Condition.wait`, etc.).
+ Specifiying a timeout greater than this value will raise an
+ :exc:`OverflowError`.
+
+
Detailed interfaces for the objects are documented below.
The design of this module is loosely based on Java's threading model. However,
@@ -349,7 +359,7 @@ and may vary across implementations.
All methods are executed atomically.
-.. method:: Lock.acquire(blocking=True)
+.. method:: Lock.acquire(blocking=True, timeout=-1)
Acquire a lock, blocking or non-blocking.
@@ -363,6 +373,15 @@ All methods are executed atomically.
without an argument would block, return false immediately; otherwise, do the
same thing as when called without arguments, and return true.
+ When invoked with the floating-point *timeout* argument set to a positive
+ value, block for at most the number of seconds specified by *timeout*
+ and as long as the lock cannot be acquired. A negative *timeout* argument
+ specifies an unbounded wait. It is forbidden to specify a *timeout*
+ when *blocking* is false.
+
+ The return value is ``True`` if the lock is acquired successfully,
+ ``False`` if not (for example if the *timeout* expired).
+
.. method:: Lock.release()
@@ -396,7 +415,7 @@ pair) resets the lock to unlocked and allows another thread blocked in
:meth:`acquire` to proceed.
-.. method:: RLock.acquire(blocking=True)
+.. method:: RLock.acquire(blocking=True, timeout=-1)
Acquire a lock, blocking or non-blocking.
@@ -415,6 +434,11 @@ pair) resets the lock to unlocked and allows another thread blocked in
without an argument would block, return false immediately; otherwise, do the
same thing as when called without arguments, and return true.
+ When invoked with the floating-point *timeout* argument set to a positive
+ value, block for at most the number of seconds specified by *timeout*
+ and as long as the lock cannot be acquired. Return true if the lock has
+ been acquired, false if the timeout has elapsed.
+
.. method:: RLock.release()