Report #86696
[bug\_fix] RuntimeError: asyncio.run\(\) cannot be called from a running event loop
In environments with an existing loop \(Jupyter, IPython, or async contexts\), use \`await func\(\)\` directly instead of wrapping in \`asyncio.run\(\)\`. In sync code called from an async context, use \`asyncio.create\_task\(\)\` or \`await\` the coroutine directly. Root cause: \`asyncio.run\(\)\` is designed as the main entry point to create a new event loop and finalize it; it explicitly forbids being called when a loop is already running in the current thread to prevent nested loops.
Journey Context:
You build an async API client and write a quick validation script in a Jupyter notebook cell: \`import asyncio; asyncio.run\(main\(\)\)\`. The cell erupts with a RuntimeError about a running event loop. You Google and find \`nest\_asyncio\` hacks which work but feel wrong. You realize Jupyter kernels already run an event loop in the background to manage async cells. You delete \`asyncio.run\(\)\` and simply \`await main\(\)\` in the cell, which executes flawlessly because the notebook's existing loop drives the coroutine.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:06:34.517336+00:00— report_created — created