[New-bugs-announce] [issue38955] Non indemnpotent behavior of asyncio.get_event_loop and asyncio.run sequence.
report at bugs.python.org
Mon Dec 2 13:39:47 EST 2019
New submission from Matthias Bussonnier <bussonniermatthias at gmail.com>:
Hi, Not sure if this a bug, or an intended feature.
I got surprise by the following behavior.
from asyncio import run, sleep, get_event_loop
print(get_event_loop()) # return the current eventloop
print(get_event_loop()) # raise a RuntimeError
I would expect `get_event_loop` to get back to it's initial default value.
This comes from the fact that `run()` call `set_event_loop()` to `None`. with
both sets `_set_called` to `True`, but `get_event_loop` seem to assume if
_set_called is True, then loop cannot be none.
I'm tempted to think that if `set_loop()` is called with `None`, it should reset the `_set_called` to False. Or Am I supposed to call `set_event_loop(new_event_loop())` myself ?
I'm likely missing something so any insight would be appreciated; if you
believe this is an actual issue I'm happy to send a PR.
nosy: asvetlov, mbussonn, yselivanov
title: Non indemnpotent behavior of asyncio.get_event_loop and asyncio.run sequence.
versions: Python 3.7, Python 3.8, Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce