By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Aug 30 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
[am*****@yahoo.com]
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.
It's a Windows bug, fixed a while ago but not yet in a released
Python; here's the bug report:

http://www.python.org/sf/1234979

2 _should_ have exactly the same effect as 1, but didn't on Windows.
If the argument to acquire is a true/false flag, the
behaviors for values of 1 and 2 ought to be the same.
Right, that's the intent.
...

Aug 30 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.