Question about threading.Lock().aquire(waitflag)

ameyer2 at yahoo.com ameyer2 at yahoo.com
Wed Aug 31 01:23:26 CEST 2005


It's not clear to me from the Python docs whether waitflag
is treated as a boolean or as a number.

Running on Windows, I get two different behaviors from
the following calls to acquire:

   aLock = threading.Lock()
   ...

   # Thread 0
   # This one often succeeds
   aLock.acquire(1)
   ...

   # Thread 1
   # When this one would fail in a different thread
   aLock.acquire(2)

but the behaviors aren't what I would expect if waitflag
were a timeout value.

If the argument to acquire is a true/false flag, the
behaviors for values of 1 and 2 ought to be the same.
If it's not a true/false flag, what is it?  It's not
clear to me that it's a timeout value - wait this many
seconds and then fail if the lock can't be acquired.

What I really need is a timed lock - which I can implement
myself by calling acquire(0) and sleeping and looping for
some time until it succeeds or times out.  But if Python
already supports this, I'd rather do it the Python way.

Thanks.




More information about the Python-list mailing list