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

Yury Selivanov yselivanov at gmail.com
Mon Jun 6 13:15:51 EDT 2016


> On Jun 5, 2016, at 11:56 AM, Ben Darnell <ben at bendarnell.com> wrote:
> 
> It has come to my attention (https://github.com/KeepSafe/aiohttp/issues/877) that Python 3.5.2 (!) introduced a new context manager asyncio.timeout, which attaches a timeout to the current asyncio.Task. Any library or application that uses this feature will not be portable to other coroutine runners.
> 
>     with asyncio.timeout(1):
>         result = await aiohttp.get('http://www.example.com')
> 
> It's difficult to make this interface portable. We'd need to introduce a global thread-specific object that all of the coroutine runners could register the current task on, and define an interface that asyncio.timeout would call on that object to set the timeout. We could get rid of the global if the context manager used `async with` instead of `with`, since that would give us a way to communicate with the coroutine runner directly, but the net result is still that each runner needs to implement hooks for this feature (the hooks may or may not be generalizable to other features in the future).

We’ve discussed this and decided that we should revert asyncio.Timeout from 3.5.2.  I’ll do that later today.

Yury


More information about the Async-sig mailing list