I'm trying to run an async function inside a Jupyter Notebook using asyncio.run() like this:
import asyncio
async def my_task():
await asyncio.sleep(1)
return "Done"
asyncio.run(my_task())
But I get this error:
RuntimeError: Event loop is closed
I understand Jupyter uses an existing event loop, but what's the correct way to run async functions inside a notebook without this error?
Also:
Why does this work in a regular .py script but not in Jupyter?
Should I use nest_asyncio, await, or some other workaround?
await my_task()and it works for me - so I solved problem in few second instead of wating few hours for answer ;)