New submission from Nathaniel Smith <[email protected]>:
Currently, if you use asyncio.wait_for(future, timeout=....) and the timeout
expires, then it (a) cancels to the future, and then (b) returns. This is fine
if the future is a Future, because Future.cancel is synchronous and completes
immediately. But if the future is a Task, then Task.cancel merely requests
cancellation, and it will complete later (or not). In particular, this means
that wait_for(coro, ...) can return with the coroutine still running, which is
surprising.
(Originally encountered by Alex Grönholm, who was using code like
async with aclosing(agen):
await wait_for(agen.asend(...), timeout=...)
and then confused about why the call to agen.aclose was raising an error
complaining that agen.asend was still running. Currently this requires an
async_generator based async generator to trigger; with a native async
generator, the problem is masked by bpo-32526.)
----------
components: asyncio
messages: 311509
nosy: asvetlov, giampaolo.rodola, njs, yselivanov
priority: normal
severity: normal
status: open
title: wait_for(future, ...) should wait for the future (even if a timeout
occurs)
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32751>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com