Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19610

Condition.wait() behavior with timeout

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ross@biostat.ucsf.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'rejected': 0.04; 'thread,': 0.04; 'python': 0.08; 'googled': 0.09; 'raised.': 0.09; 'says,': 0.09; 'underlying': 0.09; '2.7': 0.13; 'called,': 0.16; 'complains': 0.16; 'occurred.': 0.16; 'occurs.': 0.16; 'out?': 0.16; 'released.': 0.16; 'runtimeerror': 0.16; 'subject:() ': 0.16; 'subject:behavior': 0.16; 'threading': 0.16; 'timed': 0.16; 'timeout': 0.16; 'value;': 0.16; 'x-mailer:evolution 2.22.3.1': 0.16; "wouldn't": 0.17; 'acquired': 0.18; 'part,': 0.18; 'url:bugs': 0.18; '(which': 0.19; 'seems': 0.19; "haven't": 0.20; 'cc:no real name:2**0': 0.21; '(or': 0.22; 'optional': 0.23; 'refers': 0.23; 'topic.': 0.23; 'url:dev': 0.23; 'cc:2**0': 0.25; 'thanks.': 0.25; 'module': 0.26; "i'm": 0.27; 'variable': 0.27; 'seem': 0.29; '(since': 0.30; 'lock': 0.30; 'logic': 0.30; 'object.': 0.30; 'second,': 0.30; 'useless': 0.30; '2005': 0.30; '2009.': 0.30; 'pretty': 0.30; 'usually': 0.30; 'quite': 0.31; "i've": 0.31; 'anyone': 0.31; 'cases': 0.32; 'certainly': 0.32; 'returning': 0.32; 'does': 0.32; 'supposed': 0.32; 'to:addr :python-list': 0.33; 'there': 0.33; 'normally': 0.34; 'certain': 0.34; 'calling': 0.34; 'anything': 0.34; 'things': 0.35; 'response': 0.35; 'url:python': 0.36; 'thread': 0.36; 'but': 0.37; 'another': 0.37; 'hoping': 0.38; 'useful': 0.38; 'subject:with': 0.38; 'should': 0.38; 'clearly': 0.39; 'url:org': 0.39; "what's": 0.39; 'help': 0.39; 'called': 0.39; 'might': 0.40; 'to:addr:python.org': 0.40; 'your': 0.61; 'header:Message-Id:1': 0.62; 'waiting': 0.62; 'subject:skip:C 10': 0.64; 'cause': 0.66; 'proposal': 0.67; 'received:38': 0.74; 'race': 0.77; ':).': 0.84; 'condition,': 0.84; 'on?': 0.84; 'received:10.0.2': 0.84; 'returns.': 0.84; 'received:38.99': 0.91; 'scenario': 0.93
Subject Condition.wait() behavior with timeout
From Ross Boylan <ross@biostat.ucsf.edu>
To python-list@python.org
Content-Type text/plain; charset=UTF-8
Organization UCSF
Date Mon, 30 Jan 2012 12:14:33 -0800
Mime-Version 1.0
X-Mailer Evolution 2.22.3.1
Content-Transfer-Encoding quoted-printable
X-Spam_score -4.4
X-Spam_score_int -43
X-Spam_bar ----
X-Spam_report (-4.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.8 ALL_TRUSTED Passed through trusted hosts only via SMTP -2.6 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000]
Cc ross@biostat.ucsf.edu
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5221.1327954512.27778.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327954512 news.xs4all.nl 6901 [2001:888:2000:d::a6]:60316
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19610

Show key headers only | View raw


The Python 2.7 documents for the threading module says, in part,
wait([timeout])ΒΆ
        
        Wait until notified or until a timeout occurs. If the calling
        thread has not acquired the lock when this method is called, a
        RuntimeError is raised.
        
        This method releases the underlying lock, and then blocks until
        it is awakened by a notify() or notifyAll() call for the same
        condition variable in another thread, or until the optional
        timeout occurs. Once awakened or timed out, it re-acquires the
        lock and returns.
        
First, the documentation does not say what the return value is.  I was
hoping it was True or False depending on whether a timeout occurred, as
Event.wait().

Second, the "Once awakened or timed out, it re-acquires the lock and
returns" sounds very strange.  If there was a timeout then an attempt to
acquire the lock will block until it is released.  Since there was no
notify there almost certainly will be no release() immediately after the
tiemout.  Which would make the timeout pretty useless (since the thread
that called wait() blocks even after the timeout expires), and might
cause a race on the condition object.

I've googled around, but haven't found anything quite on topic.
http://bugs.python.org/issue1175933 from 2005 requested adding a timeout
to Condition.wait(), a proposal rejected in 2009.  Clearly it's there
now.

http://www.gossamer-threads.com/lists/python/dev/761847 complains there
is no return value from wait and so no way to determine if a timeout
occurred.   One response was
<quote>
>GR> How am I supposed to know if it was notified or if it timed out? 

Normally you wouldn't have to know. The logic of your program should be 
such that you wait until a certain condition is satisfied. After each 
wait you usually check that condition anyway, like: 
</quote>
http://bugs.python.org/issue1175933#msg48141 also refers to the need to
check things after returning from wait().  But both of these cases seem
to refer to a scenario in which there are many workers waiting on the
condition, not one with notify() and a single thread waiting (which is
what I'm thinking about).  The thread does say there is no return value;
it seems to me it would be useful to document that if it's still true
(or True :).

Can anyone help me understand what's going on?

Thanks.
Ross Boylan

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Condition.wait() behavior with timeout Ross Boylan <ross@biostat.ucsf.edu> - 2012-01-30 12:14 -0800

csiph-web