I use loop.close() in test() to close the event loop as shown below:
import asyncio
async def test(loop):
print("Test")
loop.stop() # Stop the event loop
loop.close() # Here
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.create_task(test(loop))
loop.run_forever()
But, I got the error below even though I use loop.stop() to stop the event loop before loop.close():
RuntimeError: Cannot close a running event loop
So, are there any ways to solve the error?