I work mainly in the IPython interactive shell. Sometimes I copy-paste code from the Internet to check it and work with examples.
If I embed the following code from this tutorial :
import asyncio async def speak_async(): print('OMG asynchronicity!') loop = asyncio.get_event_loop() loop.run_until_complete(speak_async()) loop.close()
I will close the loop. The documentation says that you should not use any methods in the event loop after closing it. And async.get_event_loop() will still return this closed loop.
async.get_event_loop()
What if I accidentally close the event loop? I would prefer not to restart the interpreter.
You can simply create and set up a new event loop for the current context ;
asyncio.set_event_loop(asyncio.new_event_loop())