[Python-checkins] r80071 - in python/branches/py3k: Doc/library/_thread.rst Doc/library/threading.rst Include/pythread.h Lib/_dummy_thread.py Lib/multiprocessing/pool.py Lib/test/lock_tests.py Lib/threading.py Misc/NEWS Modules/_threadmodule.c Python/thread_nt.h Python/thread_pthread.h

Ezio Melotti ezio.melotti at gmail.com
Mon Apr 19 09:58:33 CEST 2010


Hi,
versionadded and versionchanged should be added for the constant and the 
new parameters.

Best Regards,
Ezio Melotti

On 14/04/2010 18.44, antoine.pitrou wrote:
> Author: antoine.pitrou
> Date: Wed Apr 14 17:44:10 2010
> New Revision: 80071
>
> Log:
> 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.
>
>
>
> Modified:
>     python/branches/py3k/Doc/library/_thread.rst
>     python/branches/py3k/Doc/library/threading.rst
>     python/branches/py3k/Include/pythread.h
>     python/branches/py3k/Lib/_dummy_thread.py
>     python/branches/py3k/Lib/multiprocessing/pool.py
>     python/branches/py3k/Lib/test/lock_tests.py
>     python/branches/py3k/Lib/threading.py
>     python/branches/py3k/Misc/NEWS
>     python/branches/py3k/Modules/_threadmodule.c
>     python/branches/py3k/Python/thread_nt.h
>     python/branches/py3k/Python/thread_pthread.h
>
> Modified: python/branches/py3k/Doc/library/_thread.rst
> ==============================================================================
> --- python/branches/py3k/Doc/library/_thread.rst	(original)
> +++ python/branches/py3k/Doc/library/_thread.rst	Wed Apr 14 17:44:10 2010
> @@ -28,7 +28,7 @@
>   :mod:`_dummy_thread` module is available. It duplicates this module's interface
>   and can be used as a drop-in replacement.
>
> -It defines the following constant and functions:
> +It defines the following constants and functions:
>
>
>   .. exception:: error
> @@ -103,19 +103,34 @@
>      Availability: Windows, systems with POSIX threads.
>
>
> +.. data:: TIMEOUT_MAX
> +
> +   The maximum value allowed for the *timeout* parameter of
> +   :meth:`Lock.acquire`. Specifiying a timeout greater than this value will
> +   raise an :exc:`OverflowError`.
> +
> +
>   Lock objects have the following methods:
>
>
> -.. method:: lock.acquire([waitflag])
> +.. method:: lock.acquire(waitflag=1, timeout=-1)
>
> -   Without the optional argument, this method acquires the lock unconditionally, if
> +   Without any optional argument, this method acquires the lock unconditionally, if
>      necessary waiting until it is released by another thread (only one thread at a
> -   time can acquire a lock --- that's their reason for existence).  If the integer
> -   *waitflag* argument is present, the action depends on its value: if it is zero,
> -   the lock is only acquired if it can be acquired immediately without waiting,
> -   while if it is nonzero, the lock is acquired unconditionally as before.  The
> -   return value is ``True`` if the lock is acquired successfully, ``False`` if not.
> +   time can acquire a lock --- that's their reason for existence).
>
> +   If the integer *waitflag* argument is present, the action depends on its
> +   value: if it is zero, the lock is only acquired if it can be acquired
> +   immediately without waiting, while if it is nonzero, the lock is acquired
> +   unconditionally as above.
> +
> +   If the floating-point *timeout* argument is present and positive, it
> +   specifies the maximum wait time in seconds before returning.  A negative
> +   *timeout* argument specifies an unbounded wait.  You cannot specify
> +   a *timeout* if *waitflag* is zero.
> +
> +   The return value is ``True`` if the lock is acquired successfully,
> +   ``False`` if not.
>
>   .. method:: lock.release()
>
>
> Modified: python/branches/py3k/Doc/library/threading.rst
> ==============================================================================
> --- python/branches/py3k/Doc/library/threading.rst	(original)
> +++ python/branches/py3k/Doc/library/threading.rst	Wed Apr 14 17:44:10 2010
> @@ -155,6 +155,16 @@
>      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 @@
>   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 @@
>      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 @@
>   :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 @@
>      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()
>
>
> Modified: python/branches/py3k/Include/pythread.h
> ==============================================================================
> --- python/branches/py3k/Include/pythread.h	(original)
> +++ python/branches/py3k/Include/pythread.h	Wed Apr 14 17:44:10 2010
> @@ -19,6 +19,41 @@
> [...]



More information about the Python-checkins mailing list