no return value for threading.Condition.wait(timeout)?
pavlovevidence at gmail.com
Fri Jul 17 00:15:52 CEST 2009
On Jul 16, 2:22 pm, Maxim Khitrov <mkhit... at gmail.com> wrote:
> On Thu, Jul 16, 2009 at 5:00 PM, Carl Banks<pavlovevide... at gmail.com> wrote:
> > 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()
> You will always be the owner of the condition whether it times out or
> your thread is notified. This doesn't solve the problem.
You are correct, I misread the code. So scratch what I said.
More information about the Python-list