[Python-Dev] threading.Semaphore()'s counter can become negative for non-ints

T.B. bauertomer at gmail.com
Tue Jan 31 22:58:40 CET 2012

> I concur. This is very much a non-problem.
> There is no need to add more code and slow
> running time with superfluous type checks.
> Raymond

What do you think about the following check from threading.py:

@@ -317,8 +317,6 @@
          self._value = value

      def acquire(self, blocking=True, timeout=None):
-        if not blocking and timeout is not None:
-            raise ValueError("can't specify timeout for non-blocking 
          rc = False
(There are similar checks in Modules/_threadmodule.c)

Removing the check means that we ignore the timeout argument when 
blocking=False. Currently in the multiprocessing docs there is an 
outdated note concerning acquire() methods that also says: "If block is 
False then timeout is ignored". This makes the acquire() methods of the 
threading and multiprocessing modules have different behaviors.
Related: http://bugs.python.org/issue850728#msg103227


More information about the Python-Dev mailing list