no return value for threading.Condition.wait(timeout)?
Carl Banks
pavlovevidence at gmail.com
Thu Jul 16 17:00:43 EDT 2009
On Jul 16, 8:12 am, Gabriel Rossetti <gabriel.rosse... at arimaz.com>
wrote:
> Hello everyone,
>
> I am using threading.Condition.wait(timeout) and was surprised to see
> that there is no return value nor an exception when wait() is used w/ a
> timeout. How am I supposed to know if it was notified or if it timed out?
That's a good question. Condition.wait seems to violate an invariant
if it can return without having acquired the underlying lock. And if
it does the least it could do is to return a status so you know if you
have to skeddadle.
Workaround is to use the _is_owned() method of Condition to see if you
are the owner of the condition, but this method is undocumented.
cond = Condition()
...
cond.acquire()
while not ok_to_proceed():
cond.wait()
if not cond._is_owned():
# must've timed out
raise TimeOutException
operate()
cond.release()
Carl Banks
More information about the Python-list
mailing list