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

Guido van Rossum guido at python.org
Fri May 20 14:04:25 EDT 2016


On Fri, May 20, 2016 at 10:53 AM, Ilya Kulakov <kulakov.ilya at gmail.com> wrote:
>
> On 20 May 2016, at 12:22, Guido van Rossum <guido at python.org> wrote:
>
> > OK, I finally see the point. There are legitimate situations where
> > get_event_loop() returns None (this is how most of asyncio's tests are
> > running).
>
>
> Unless there are tests that expect that get_event_loop() would return None
> when called from within coroutine it should be fine.

The tests are supposed to fail if something doesn't explicitly pass
the loop; this is how we test that all code in asyncio itself always
correctly passes the loop rather than accidentally relying on
get_event_loop().

> > So we want a separate function, e.g.
> > get_current_event_loop(). Send a PR to the GitHub project.
>
>
> Also see related bug: http://bugs.python.org/issue26969
> Yuri did some work, but he argumented in favor of modifying get_event_loop.
>
> Should we continue discussion of implementation here or in that issue?

I consider it a feature that you can make get_event_loop() return
None. But I think it would be a bug (in the Policy class) if it
returned some other loop that's not the one that's running.

I also think it's fine for a particular library or app to request that
get_event_loop() not return None. User code is simpler that way.

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


More information about the Python-ideas mailing list