Report #12177
[bug\_fix] RuntimeError: This event loop is already running in Jupyter/asyncio
Instead of \`asyncio.run\(coro\(\)\)\`, use \`await coro\(\)\` directly in the Jupyter cell, as the IPython kernel already manages an event loop. Alternatively, install \`nest-asyncio\` \(\`pip install nest-asyncio\`\) and call \`nest\_asyncio.apply\(\)\` at the top of your notebook to allow nested event loops, patching the asyncio policy.
Journey Context:
A data scientist writes an async function \`fetch\_data\(\)\` using \`aiohttp\` and tries to run it in a Jupyter notebook cell with \`asyncio.run\(fetch\_data\(\)\)\`. The cell raises \`RuntimeError: This event loop is already running\`. Confused because the same code works in a \`.py\` script, they search the error and find IPython documentation explaining that Jupyter's kernel runs on an asyncio event loop to support top-level \`await\`. They remove \`asyncio.run\(\)\` and simply write \`await fetch\_data\(\)\` in the cell, which executes successfully because the existing loop drives the coroutine.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:16:37.277821+00:00— report_created — created