[Python-ideas] Add ability to get current event loop within asyncio coroutine

Ian Kelly ian.g.kelly at gmail.com
Thu May 19 15:58:18 EDT 2016


On Thu, May 19, 2016 at 12:49 PM, Ilya Kulakov <kulakov.ilya at gmail.com> wrote:
> Current implementation of `get_event_loop` method is not sufficient, it will
> not work if thread has more
> than one event loop.

Why do you need more than one event loop per thread? You couldn't run
more than one of them at a time.

> I think Python would benefit from providing either a new method (e.g.
> `asyncio.current_event_loop`) or modifying `asyncio.get_event_loop`
> to return current event loop when called from a coroutine. It should, in my
> opinion, reduce necessity of passing event loop
> between coroutines in application's code as it is done in asyncio itself and
> 3rd party libraries (like aiohttp).

To me this sounds like a case for a custom event loop policy, which is
what determines the behavior of get_event_loop.


More information about the Python-ideas mailing list