Report #104487
[bug\_fix] RuntimeError: This event loop is already running \(in asyncio\)
Use \`nest\_asyncio.apply\(\)\` to allow nested event loops, or restructure code to avoid calling \`asyncio.run\(\)\` from within a running event loop \(e.g., use \`asyncio.get\_running\_loop\(\)\` instead\).
Journey Context:
A developer was using Jupyter Notebook and tried to run \`asyncio.run\(main\(\)\)\` inside a cell. They got \`RuntimeError: This event loop is already running\`. Jupyter itself runs an asyncio event loop in the background. Calling \`asyncio.run\(\)\` attempts to start a new event loop, which is not allowed when one is already active. The developer searched online and found the \`nest\_asyncio\` package, which patches the event loop to allow nested loops. After installing \(\`pip install nest\_asyncio\`\) and adding \`import nest\_asyncio; nest\_asyncio.apply\(\)\` at the top of the notebook cell, the error disappeared. Another fix is to not use \`asyncio.run\(\)\` but instead use \`await main\(\)\` directly in an async cell \(if the notebook supports it\). The root cause: Python's asyncio event loop is per-thread and cannot be re-entered. Jupyter's default loop prevents new loops. \`nest\_asyncio\` is the widely accepted workaround for interactive environments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-23T20:07:02.072033+00:00— report_created — created