Report #100966
[bug\_fix] RuntimeError: This event loop is already running when calling asyncio.run inside a Jupyter notebook or another running loop
In an environment that already has a running loop \(Jupyter, IPython, pytest-asyncio\), use await coro\(\) directly, or nest loops with asyncio.run\_coroutine\_threadsafe, or use nest\_asyncio.apply\(\). In standalone scripts, keep asyncio.run at top-level only.
Journey Context:
You have an async function fetch\(\) and write asyncio.run\(fetch\(\)\) in a Jupyter cell. It explodes with RuntimeError: This event loop is already running. You check the code and it works in a .py file. The difference is that Jupyter/IPython already starts an event loop to drive the kernel, so asyncio.run tries to create a second loop and fails. The actual fix depends on context: inside Jupyter you can just await fetch\(\); if you need to run async code inside a synchronous callback you can use asyncio.run\_coroutine\_threadsafe; for quick compatibility you can apply nest\_asyncio, which patches the loop to allow nesting.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:45:33.782396+00:00— report_created — created