Skip to content


Running asyncio task in Databricks

Standard method to run asyncio task is as simple as 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)

RuntimeError: cannot be called from a running event loop

Indeed, in Databricks, we've already in a running loop:

import asyncio

<_UnixSelectorEventLoop running=True closed=False debug=False>

Databricks job/task context

Suppose we're running following job/task in a Azure Databricks workspace:

jobId: "1111"
jobRunId: "2222"
taskRunId: "3333"
jobName: "ths job name"
taskName: "first-task"

Run below command in a Databricks job (task precisely):