Report #16679
[bug\_fix] RuntimeError: no running event loop when calling asyncio.run\(\) inside Jupyter/IPython
In Jupyter notebooks, use \`await\` directly on the coroutine object \(e.g., \`await fetch\_data\(\)\`\) instead of \`asyncio.run\(fetch\_data\(\)\)\`, or apply \`nest\_asyncio.apply\(\)\` to allow nested event loops.
Journey Context:
Developer writes an async function \`async def fetch\(\): return await aiohttp.get\(...\)\` and wants to test it in a Jupyter notebook cell. They call \`asyncio.run\(fetch\(\)\)\` as they would in a standard script. However, IPython/Jupyter \(since version 5\+\) already maintains a running asyncio event loop in the kernel to handle async cell execution and comms. \`asyncio.run\(\)\` is designed to create a new event loop, set it as the current loop for the thread, and close it afterward. It explicitly checks if a loop is already running and raises \`RuntimeError: asyncio.run\(\) cannot be called from a running event loop\` \(or similar\). The developer searches for the error and finds references to \`asyncio.get\_event\_loop\(\)\`, but that also warns about deprecation or returns the running loop. The solution is to recognize that Jupyter already provides a running loop, so the coroutine can be awaited directly in the cell, or use the \`nest\_asyncio\` library to patch the loop to allow nested \`asyncio.run\` calls.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:17:56.844885+00:00— report_created — created