Report #69055
[bug\_fix] RuntimeError: This event loop is already running \(in Jupyter/IPython\)
In Jupyter Notebook/Lab, use \`await my\_coroutine\(\)\` directly in a cell without \`asyncio.run\(\)\`. Alternatively, if you must use \`asyncio.run\(\)\` or a library that calls it, install and apply \`nest\_asyncio\`: \`import nest\_asyncio; nest\_asyncio.apply\(\)\` at the start of the notebook.
Journey Context:
You develop an async function \`fetch\_data\(\)\` using \`aiohttp\`. In a regular script, you wrap it in \`asyncio.run\(fetch\_data\(\)\)\` and it works. You open Jupyter Lab to prototype, paste the same code into a cell, and execute it. It immediately raises \`RuntimeError: This event loop is already running\`. You check \`asyncio.get\_event\_loop\(\).is\_running\(\)\` and it returns True because Jupyter's kernel runs on an event loop. You find that \`asyncio.run\(\)\` explicitly prohibits being called from a thread with a running loop. You discover that in Jupyter you can simply \`await fetch\_data\(\)\` directly in the cell. For nested libraries that internally call \`asyncio.run\(\)\`, you find the \`nest\_asyncio\` library which patches the event loop to allow nesting, solving the issue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T22:23:27.042053+00:00— report_created — created