RuntimeError: Event Loop Already Running

RuntimeError: This event loop is already running

Quick Answer

You are calling asyncio.run() from inside an already running event loop. In Jupyter notebooks, use 'await' directly. In other contexts, use asyncio.create_task().

Why This Happens

asyncio event loops cannot be nested. If you call asyncio.run() from a Jupyter notebook or inside an async function, you get this error.

The Problem

import asyncio
async def fetch(): return 'data'
# In Jupyter:
asyncio.run(fetch())

The Fix

# In Jupyter, just await:
result = await fetch()

# Or use nest_asyncio:
import nest_asyncio
nest_asyncio.apply()
asyncio.run(fetch())

Step-by-Step Fix

  1. 1

    Use await in Jupyter

    Use 'await coroutine()' directly.

  2. 2

    Install nest_asyncio

    pip install nest_asyncio and call nest_asyncio.apply().

  3. 3

    Restructure code

    Use a single asyncio.run() at the top level.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free