Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31135
| References | <CAAGqYJ22hAdr3-UVeXM_TEwfP_uGu8JoCdh_LHjWOyH2cRphwQ@mail.gmail.com> <mailman.2019.1349831812.27098.python-list@python.org> <nl5gk9-0t5.ln1@satorlaser.homedns.org> <CALwzidm6ouGh-VSunL=8E7CzY0d7gThvGu-in9cu01kNY6qTkA@mail.gmail.com> |
|---|---|
| Date | 2012-10-11 15:06 -0700 |
| Subject | Re: an error in python lib? |
| From | Wenhua Zhao <whzhao@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2069.1349993211.27098.python-list@python.org> (permalink) |
> On Wed, Oct 10, 2012 at 6:18 AM, Ulrich Eckhardt
>> The comment clearly states "owned by current thread", not "owned by any
>> thread". The latter would also be useless, as that can change concurrently
>> at any time when owned by a different thread, so making decisions on this
>> state is futile.
Agree.
On Wed, Oct 10, 2012 at 12:21 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> Can you demonstrate an API bug that is caused by this?
A simple demo of this error is:
-----------8<------------------------8<----------------------
import time
from threading import Condition, Lock, Thread
cv = Condition(Lock())
def do_acquire():
cv.acquire()
print "cv acquired in thread"
time.sleep(5)
cv.release()
print "cv released in thread"
thread = Thread(target=do_acquire)
thread.start()
for i in range(10):
print "in main cv._is_owned: ", cv._is_owned()
time.sleep(1)
-----------8<------------------------8<----------------------
The condition variable is only acquired in the thread, so in main it should
always print false. However, my output gives:
$ python test.py
cv acquired in threadin main cv._is_owned:
True
in main cv._is_owned: True
in main cv._is_owned: True
in main cv._is_owned: True
in main cv._is_owned: True
cv released in thread
in main cv._is_owned: False
in main cv._is_owned: False
in main cv._is_owned: False
in main cv._is_owned: False
in main cv._is_owned: False
However, as long as you follow the generic pattern, i.e. always use
acquire() before wait(), this error is not triggered.
Thanks all.
Wenhua
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: an error in python lib? MRAB <python@mrabarnett.plus.com> - 2012-10-10 02:16 +0100
Re: an error in python lib? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-10 14:18 +0200
Re: an error in python lib? Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-10 13:21 -0600
Re: an error in python lib? Wenhua Zhao <whzhao@gmail.com> - 2012-10-11 15:06 -0700
Re: an error in python lib? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-12 09:15 +0200
csiph-web