[issue38955] Non indemnpotent behavior of asyncio.get_event_loop and asyncio.run sequence.

Andrew Svetlov report at bugs.python.org
Tue Dec 3 05:42:52 EST 2019


Andrew Svetlov <andrew.svetlov at gmail.com> added the comment:

I think now it is too late for changing the behavior.
In the ideal world, get_event_loop() should never exist, maybe we can deprecate/remove it eventually.
run() should be used for executing async code; get_running_loop() for getting a reference to the currently executed loop.
It may help to avoid many silly problems.
Maybe some scenarios are not covered but at least high-level code can be organized this way.

P.S.
set_event_loop(None) is not for resetting to default but for disabling of the default loop creation for the current thread. Non-main threads work like set_event_loop(None) was called implicitly.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38955>
_______________________________________


More information about the Python-bugs-list mailing list