[Async-sig] asyncio.timeout() is not portable

Ben Darnell ben at bendarnell.com
Sun Jun 12 12:00:58 EDT 2016


On Sun, Jun 5, 2016 at 11:38 AM, Nathaniel Smith <njs at pobox.com> wrote:

>
> And AFAICT the tornado.gen.with_timeout wrapper doesn't deal with
> coroutines/coroutine runners at all?


It doesn't currently, but this is a bug. It should be creating a coroutine
runner for the input task if it is not already a Future.


> I just read the source, but I
> couldn't fully follow it. If I write
>   async def do_stuff():
>       try:
>           await aiohttp.get("https://python.org")
>       except:
>           print("oops, cleaning up")
>           raise
>       else:
>           print("did it!")
>   await tornado.gen.with_timeout(timedelta(seconds=0.0001), do_stuff())
> and the timeout fires, then is the output "oops, cleaning up", "did
> it!", or nothing at all?
>

This would not produce any output: Tornado doesn't do asyncio-style
cancellation (I've had enough bad experiences with KeyboardInterrupt
cropping up at unexpected times). The inner task has its own coroutine
runner and will continue after the outer task has stopped waiting for it.
This allows the Future from the inner task to be reused (either in the same
outer task or in another task), but it does require that some lower-level
timeout mechanism also be present to prevent timed-out tasks from
accumulating forever. This is not ideal and it would be good to allow the
inner task to find out its been canceled (the reusability of Futures only
matters in rare cases).

-Ben


>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/async-sig/attachments/20160612/80dfbc84/attachment.html>


More information about the Async-sig mailing list