Semaphore.acquire() accepts timeout=-1

This commit is contained in:
Victor Stinner
2015-01-06 16:31:41 +01:00
committed by Sergey Shepelev
parent a332f2a8e6
commit 4f3eaa0f54

View File

@@ -78,9 +78,17 @@ class Semaphore(object):
When invoked with blocking set to false, do not block. If a call without
an argument would block, return false immediately; otherwise, do the
same thing as when called without arguments, and return true.
Timeout value must be strictly positive.
"""
if not blocking and timeout is not None:
if timeout == -1:
timeout = None
if timeout is not None and timeout < 0:
raise ValueError("timeout value must be strictly positive")
if not blocking:
if timeout is not None:
raise ValueError("can't specify timeout for non-blocking acquire")
timeout = 0
if not blocking and self.locked():
return False