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

Guido van Rossum guido at python.org
Thu May 19 15:09:58 EDT 2016

Can you explain why asyncio.get_event_loop() doesn't do what you want?

On Thu, May 19, 2016 at 11:49 AM, Ilya Kulakov <kulakov.ilya at gmail.com> wrote:
> asyncio is a great library which with recent changes in 3.5 was made even
> better.
> However there is an inconvenience that bothers me and looks very unnatural:
> inability to access event loop
> that executes a coroutine from within that coroutine.
> This is unnatural, because we have `self` and `cls` to access object from a
> method it is bound to,
> we have `current_thread` to get an instance of Thread that currently
> executes code, but for a coroutine
> we have no such method, we cannot get its context of execution.
> Current implementation of `get_event_loop` method is not sufficient, it will
> not work if thread has more
> than one event loop.
> 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).
> Best Regards,
> Ilya Kulakov
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list