Report #42551
[bug\_fix] RuntimeError: This event loop is already running \(asyncio in Jupyter\)
Install and import \`nest\_asyncio\`, then call \`nest\_asyncio.apply\(\)\` at the top of the notebook to patch the event loop to allow nested execution, or use \`await\` directly on coroutines in Jupyter cells.
Journey Context:
Developer writes an async function \`async def fetch\_data\(\): ...\` using \`aiohttp\`. In a Jupyter notebook cell, they try to run it with \`asyncio.run\(fetch\_data\(\)\)\` or by getting the loop with \`asyncio.get\_event\_loop\(\).run\_until\_complete\(fetch\_data\(\)\)\`. Jupyter kernels \(IPython\) already run an asyncio event loop to handle async kernel operations. \`asyncio.run\(\)\` tries to create a new loop, finds one already active, and raises RuntimeError. The developer tries to get the current loop and run in it, but \`run\_until\_complete\` also fails because the loop is already running. After searching, they find that Jupyter requires \`nest\_asyncio\` to patch the loop to allow reentrant execution, or they can simply write \`await fetch\_data\(\)\` directly in the cell because Jupyter automatically awaits top-level coroutines.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:53:32.702553+00:00— report_created — created