Report #104428
[bug\_fix] RuntimeError: asyncio.run\(\) cannot be called from a running event loop
Use \`nest\_asyncio.apply\(\)\` from the \`nest\_asyncio\` package to patch the event loop, or restructure the code to avoid nested event loops \(e.g., use \`await\` instead of \`asyncio.run\(\)\` inside async functions\).
Journey Context:
Developer was running an async script inside a Jupyter notebook. The script used \`asyncio.run\(main\(\)\)\` at the top level, but Jupyter already has a running event loop. The error appeared immediately. They searched Stack Overflow and found references to \`nest\_asyncio\`. After installing \`pip install nest\_asyncio\` and adding \`import nest\_asyncio; nest\_asyncio.apply\(\)\` at the start of the notebook, the script ran without error. The root cause is that \`asyncio.run\(\)\` creates a new event loop and cannot be called when one is already active \(common in interactive environments like Jupyter, IPython, or when using \`asyncio.run\` inside another async function\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-16T20:06:36.831696+00:00— report_created — created