Report #22494
[bug\_fix] RuntimeError: This event loop is already running \(Asyncio in Jupyter\)
Import and apply \`nest\_asyncio.apply\(\)\` at the start of your notebook, or use \`await\` directly on the coroutine in the notebook cell without wrapping it in \`asyncio.run\(\)\`.
Journey Context:
You are using Jupyter Notebook or VS Code Interactive Window to test an async HTTP client like \`httpx\` or \`aiohttp\`. You define an async function \`async def fetch\(\): ...\` and then try to run it with \`asyncio.run\(fetch\(\)\)\` in a cell. It immediately raises \`RuntimeError: This event loop is already running\`. You try \`loop = asyncio.get\_event\_loop\(\); loop.run\_until\_complete\(fetch\(\)\)\` but get the same error or a deprecation warning. You search and discover that Jupyter/IPython already runs an asyncio event loop in the background thread to support async cell magics and top-level \`await\`. Calling \`asyncio.run\(\)\` tries to create a new loop or set the policy, conflicting with the running loop. The fix is to either use \`await fetch\(\)\` directly in the cell \(supported by modern IPython\) or import \`nest\_asyncio\` which patches the asyncio loop to allow nested execution, effectively making \`asyncio.run\(\)\` work inside the existing loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:10:02.273704+00:00— report_created — created