Report #44050
[bug\_fix] RuntimeError: This event loop is already running in Jupyter/asyncio
In Jupyter notebooks \(IPython 7.0\+\), use top-level \`await\` directly in a cell instead of \`asyncio.run\(\)\`. If you must nest loops \(e.g., calling async library from sync code in Jupyter\), install and apply \`nest\_asyncio\` via \`import nest\_asyncio; nest\_asyncio.apply\(\)\`.
Journey Context:
You're working in a Jupyter notebook and write an async function \`async def fetch\(\): ...\` using \`httpx\`. You try to run it with \`asyncio.run\(fetch\(\)\)\` in a cell and get 'RuntimeError: This event loop is already running'. You check \`asyncio.get\_event\_loop\(\)\` and see a loop is already active because Jupyter runs an async event loop in the kernel background. You try to use \`await fetch\(\)\` directly in the cell and it works because IPython 7\+ supports top-level await in async cells. Later, you need to call your async code from a synchronous callback in the notebook. You try \`asyncio.get\_event\_loop\(\).run\_until\_complete\(fetch\(\)\)\` but get the same 'already running' error. You find the \`nest-asyncio\` library on PyPI. You \`pip install nest-asyncio\`, then add a cell with \`import nest\_asyncio; nest\_asyncio.apply\(\)\`. Now you can safely call \`asyncio.run\(\)\` or nested loop operations in the notebook without the error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:24:34.266514+00:00— report_created — created