Report #11856
[bug\_fix] RuntimeError: This event loop is already running
Jupyter \(IPython\) kernels already have an event loop running in the background to handle async kernel operations. When you try to run \`asyncio.run\(\)\` or \`loop.run\_until\_complete\(\)\` inside a Jupyter cell, it tries to create a new loop or take control of the already running one, causing the error. The fix is to use \`await\` directly in the cell \(IPython supports top-level await\), or if you need to run async code in a sync context, install and use \`nest\_asyncio\` which patches the loop to allow nesting: \`import nest\_asyncio; nest\_asyncio.apply\(\)\`.
Journey Context:
You're working in a Jupyter Notebook with Python 3.9, fetching data with \`aiohttp\`. You write a cell: \`import asyncio; import aiohttp; async def fetch\(\): ...; asyncio.run\(fetch\(\)\)\`. When you execute the cell, you get \`RuntimeError: This event loop is already running\`. You search the error and find references to Tornado \(Jupyter's backend\) already having a loop. You try \`loop = asyncio.get\_event\_loop\(\); loop.run\_until\_complete\(fetch\(\)\)\` and get the same error. You realize Jupyter IPython runs its own async event loop to handle comms. You discover that Jupyter cells support \`await\` directly at the top level. You change the cell to just \`await fetch\(\)\` and it works because IPython compiles the cell with \`async def\` wrapper automatically. Alternatively, you install \`nest-asyncio\`, apply the patch, and \`asyncio.run\(\)\` works because it allows nested loops.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:24:20.937762+00:00— report_created — created