Condition.wait(0.5) doesn't respect it's timeout

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Apr 18 00:32:57 EDT 2009


En Fri, 17 Apr 2009 22:20:11 -0300, <stephane.bisinger at gmail.com> escribió:

> I have a problem with Condition.wait(), it doesn't return after the
> given timeout. The thing is that if I try to create a simple program,
> it works as expected, but in the actual code, the timeout is not
> respected (albeit the notify()s work as expected). [...]
>
> Has anyone the slightest idea on what I may be doing wrong? Or am I
> just lucky enough to have stumbled across a bug?

Looks like a real bug :(

> Maybe pollution from
> another module in other parts of the code? (Like gobject...)
>
> Anyway just for completeness here is a sample program that works for
> me:
>
> from threading import Thread
> from threading import Condition
>
> def some_func():
>     while True:
>         cond.acquire()
>         while True:
>             cond.wait(0.5)
>             print "Hello, world!"
>
> cond = Condition()
> thread = Thread(target=some_func)
> thread.start()

If another thread has acquired the lock, cond.wait() doesn't return. Add  
these lines at the end of your test and see:

sleep(2)
print "Main thread - cond.acquire()"
cond.acquire()
sleep(2)
print "Main thread - cond.release()"
cond.release()
sleep(2)
sys.exit()

The timeout is detected, but the wait method doesn't return, it's stuck at  
the last line (trying to restore a saved RLock state).
I don't understand the logic behind that.
Please file a bug report at http://bugs.python.org/

-- 
Gabriel Genellina




More information about the Python-list mailing list