When trying to run the asyncio hello world code example given in the docs:
import asyncio
async def hello_world():
print("Hello World!")
loop = asyncio.get_event_loop()
# Blocking call which returns when the hello_world() coroutine is done
loop.run_until_complete(hello_world())
loop.close()
I get the error:
RuntimeError: Event loop is closed
I am using python 3.5.3.
You have already called
loop.close()
before you ran that sample piece of code, on the global event loop:You need to create a new loop:
You can set that as the new global loop with:
and then just use
asyncio.get_event_loop()
again.Alternatively, just restart your Python interpreter, the first time you try to get the global event loop you get a fresh new one, unclosed.