Report #83391
[bug\_fix] RuntimeError: asyncio.run\(\) cannot be called from a running event loop
If inside an already running loop \(like in a Jupyter notebook or an async web framework handler\), await the coroutine directly \(e.g., \`await my\_coroutine\(\)\`\) instead of wrapping it in \`asyncio.run\(\)\`. For nested loops in libraries, use \`asyncio.new\_event\_loop\(\)\` with manual loop management or \`nest-asyncio\`.
Journey Context:
A developer writes an async function \`async def fetch\_data\(\): ...\` using \`aiohttp\`. In a Jupyter Notebook cell, they write \`import asyncio; asyncio.run\(fetch\_data\(\)\)\`. When they execute the cell, they get a RuntimeError because Jupyter already has a tornado-based event loop running in the background. The developer tries to use \`asyncio.get\_event\_loop\(\).run\_until\_complete\(fetch\_data\(\)\)\` which gives the same error or a DeprecationWarning. They search online and find references to \`nest\_asyncio\`. They apply \`import nest\_asyncio; nest\_asyncio.apply\(\)\` and then \`asyncio.run\(\)\` works. Alternatively, they realize they can simply write \`await fetch\_data\(\)\` directly in the Jupyter cell because the IPython kernel handles the await at the top level by scheduling it on the existing loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:33:30.259049+00:00— report_created — created