Report #84952
[bug\_fix] RuntimeError: This event loop is already running
In Jupyter/IPython, use \`await coro\(\)\` directly in a cell \(IPython handles the running loop\). In scripts where \`asyncio.run\(\)\` is called nested inside an already async context, refactor to use \`await\` or use \`asyncio.new\_event\_loop\(\)\` with manual \`loop.run\_until\_complete\(\)\` if absolutely necessary. For Jupyter specifically, install and use \`nest-asyncio\` \(\`import nest\_asyncio; nest\_asyncio.apply\(\)\`\) to allow nested event loops.
Journey Context:
A developer writes an async function \`async def fetch\(\): ...\` and uses \`asyncio.run\(fetch\(\)\)\` at the bottom of a script. It works fine when run as \`python script.py\`. They then move the code into a Jupyter notebook cell. Running the cell raises \`RuntimeError: This event loop is already running\`. They investigate and find that Jupyter kernels run an event loop in the background to handle async kernel messaging. They try removing \`asyncio.run\(\)\` and just using \`await fetch\(\)\` in the cell, which works because the cell is already in an async context handled by IPython. Alternatively, they find \`nest-asyncio\` which patches asyncio to allow nested loops, allowing them to use libraries that call \`asyncio.run\(\)\` internally within Jupyter.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:10:49.308514+00:00— report_created — created