This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Semaphore.acquire() timeout parameter
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pitrou Nosy List: aptshansen, asvetlov, hdima, pitrou, torsten
Priority: normal Keywords: patch

Created on 2003-11-28 12:47 by hdima, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
threading.diff hdima, 2003-11-28 12:47 Lib/, Doc/lib/libthreading.tex
sem_timeout.diff torsten, 2010-02-19 23:46 updated patch for py3k
sem_timeout_trunk.diff torsten, 2010-02-20 00:01 diff for trunk (2.7)
Messages (9)
msg44957 - (view) Author: Dmitry Vasiliev (hdima) Date: 2003-11-28 12:47
New optional timeout parameter for Semaphore.acquire().

acquire(block=True, timeout=None)

When invoked with blocking set to true and timeout set to
a positive number, it blocks at most timeout seconds
and return false if the internal counter is still zero;
otherwise return true.

msg44958 - (view) Author: Stephen Hansen (aptshansen) Date: 2007-03-16 07:08
This applies cleanly against the HEAD, and passes all of the threading tests. I don't see any reason NOT to have a timeout on the Semaphores, and the implementation is clean enough.

I do think that it should have some tests written since its a newish feature before being accepted, though.
msg99602 - (view) Author: Torsten Landschoff (torsten) * Date: 2010-02-19 23:46
I have been bitten by this omission from the python libs recently. I ended up copying the code from this diff into my script.

I'd rather have this available with each python installation, so I updated the patch to include test cases as well as ReST documentation updates. Attached is the patch for Python 3.x (against current py3k). I'll send an updated patch for 2.7 as well.
msg99605 - (view) Author: Torsten Landschoff (torsten) * Date: 2010-02-20 00:01
Here is the diff for Python 2.7
msg100031 - (view) Author: Torsten Landschoff (torsten) * Date: 2010-02-24 12:03
I just noticed that the multiprocessing module supports the timeout parameter of Semaphore. So the patch would also fix the documentation of multiprocessing.Semaphore since it refers to threading.Semaphore.
msg100053 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-02-24 17:34
See issue7316 for something more or less related.
msg103227 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-04-15 16:05
2.7 is in (mostly) feature freeze mode, so I'm retargetting this to 3.2.
(yes, this issue is very old; sorry)
I will try to include it (or a variant thereof; the non-blocking + timeout combination doesn't make much sense, so I plan to forbid it) to the py3k branch soon.
msg103457 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-04-17 23:53
Modified patch committed in r80157 (py3k). Thank you!
msg120651 - (view) Author: Torsten Landschoff (torsten) * Date: 2010-11-06 22:11
Thanks for applying!
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39617
2010-11-06 22:11:46torstensetmessages: + msg120651
2010-04-17 23:53:11pitrousetstatus: open -> closed
resolution: fixed
messages: + msg103457

stage: patch review -> resolved
2010-04-15 16:05:08pitrousetassignee: pitrou
stage: test needed -> patch review
messages: + msg103227
versions: - Python 2.7
2010-04-15 11:52:44asvetlovsetnosy: + asvetlov
2010-02-24 17:34:49pitrousetnosy: + pitrou
messages: + msg100053
2010-02-24 12:03:10torstensetmessages: + msg100031
2010-02-20 00:01:31torstensetfiles: + sem_timeout_trunk.diff

messages: + msg99605
2010-02-19 23:46:30torstensetfiles: + sem_timeout.diff
versions: + Python 3.2
nosy: + torsten

messages: + msg99602
2009-02-14 12:31:50ajaksu2setstage: test needed
type: enhancement
versions: + Python 2.7, - Python 2.4
2003-11-28 12:47:33hdimacreate