This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: No timeout for asyncio.Event.wait() or asyncio.Condition.wait() ?
Type: enhancement Stage:
Components: asyncio Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ajaborsk, gvanrossum, python-dev, vstinner, yselivanov
Priority: normal Keywords:

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:05adminsetgithub: 66161
2015-01-29 23:38:27vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg235004
2015-01-29 23:37:34python-devsetnosy: + python-dev
messages: + msg235003
2014-07-11 20:46:43vstinnersetmessages: + msg222794
2014-07-11 20:23:50ajaborskcreate