Report #38877
[bug\_fix] RuntimeError: This event loop is already running in Jupyter/IPython
Use \`await fetch\_data\(\)\` directly in the Jupyter cell \(IPython 7\+ automatically awaits coroutines in the top-level await\). If the code is inside a library function that calls \`asyncio.run\(\)\`, apply \`nest\_asyncio\` to patch the loop: \`import nest\_asyncio; nest\_asyncio.apply\(\)\`. This allows nested loop execution.
Journey Context:
A developer writes an async function \`async def fetch\(\): return await aiohttp.get\(...\).json\(\)\`. In a Jupyter notebook cell, they call it with the standard pattern \`import asyncio; asyncio.run\(fetch\(\)\)\`. The IPython kernel already runs an event loop in a background thread to handle UI and comms. When \`asyncio.run\(\)\` tries to create a new loop and set it as the current thread's loop, it detects the existing loop and raises \`RuntimeError\`. The developer tries \`loop = asyncio.get\_event\_loop\(\)\` which returns the existing loop, but \`loop.run\_until\_complete\(\)\` fails because the loop is already running. They discover IPython 7\+ allows top-level \`await\`, or they use \`nest\_asyncio\` to patch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:43:55.454060+00:00— report_created — created