Running asyncio task in Databricks
Standard method to run asyncio task is as simple as asyncio.run(main())
. But in Databricks, it is not that simple. With the same command, you will get the following error:
import asyncio
async def main():
await asyncio.sleep(1)
asyncio.run(main())
RuntimeError: asyncio.run() cannot be called from a running event loop
Indeed, in Databricks, we've already in a running loop:
import asyncio
asyncio.get_running_loop()
<_UnixSelectorEventLoop running=True closed=False debug=False>