From 4f3eaa0f544b61a345dab6ff1cc1fe9de20ee21e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 6 Jan 2015 16:31:41 +0100 Subject: [PATCH] Semaphore.acquire() accepts timeout=-1 --- eventlet/semaphore.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/eventlet/semaphore.py b/eventlet/semaphore.py index 962b304..b2ef9d3 100644 --- a/eventlet/semaphore.py +++ b/eventlet/semaphore.py @@ -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: - raise ValueError("can't specify timeout for non-blocking acquire") + 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