I work mostly in IPython's interactive shell. Sometimes I copy-paste code from the Internet to test it out and work with examples.
If I paste 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 not to use any methods on an event loop after it's been closed. And async.get_event_loop()
will still return that closed loop.
What should I do if I accidentally close an event loop? I would rather not restart the interpreter.
You could just create and set a new event loop for the current context;
asyncio.set_event_loop(asyncio.new_event_loop())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With