Issue 21962: No timeout for asyncio.Event.wait() or asyncio.Condition.wait() ? (original) (raw)

Issue21962

Created on 2014-07-11 20:23 by ajaborsk, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg222791 - (view) Author: Alexandre JABORSKA (ajaborsk) Date: 2014-07-11 20:23
Hi, Nor asyncio.Event.wait() neither asyncio.Condition.wait() (or .wait_for()) has a timeout parameter, while threading.Event.wait() has one. A timeout can be specified for the whole task using asyncio.wait_for() but it's tricky. I guess asyncio implementation could allow a timeout parameter (but I've not looked at the code yet). Maybe is this a feature ?
msg222794 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-07-11 20:46
> A timeout can be specified for the whole task using asyncio.wait_for() but it's tricky. Exactly, you can use wait_for() on any async operation. Why would you like to add a timeout on each async operation, while wait_for() is available? Replace event.wait(timeout=60) with wait_for(event.wait(), 60). Maybe we should put more examples using wait_for() on operations commonly used with a timeout? Guido proposed to add a timeout for some operations, but with a different meaning: maximum time without getting new events, each new event resets the timeout. It was maybe on StreamReader.readline() which uses multiple async read until it gets a full line.
msg235003 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-29 23:37
New changeset 21010940f8c1 by Victor Stinner in branch '3.4': Issue #21962, asyncio doc: Suggest the usage of wait_for() to replace https://hg.python.org/cpython/rev/21010940f8c1
msg235004 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-29 23:38
Ok, I made a minimal change to the asyncio documentation to suggest the usage of wait_for(). If you would like to enhance the documentation (ex: add some examples), please write a patch.
History
Date User Action Args
2022-04-11 14:58:05 admin set github: 66161
2015-01-29 23:38:27 vstinner set status: open -> closedresolution: fixedmessages: +
2015-01-29 23:37:34 python-dev set nosy: + python-devmessages: +
2014-07-11 20:46:43 vstinner set messages: +
2014-07-11 20:23:50 ajaborsk create