Report #97162
[bug\_fix] asyncio RuntimeError: This event loop is already running \(often in Jupyter, IPython, or pytest-asyncio\)
In an environment that already has a running loop, do not call \`asyncio.run\(\)\`. Await the coroutine directly \(\`await my\_coro\(\)\`\). If you must nest event loops \(for example in Jupyter or an interactive shell\), install and apply \`nest\_asyncio\`: \`import nest\_asyncio; nest\_asyncio.apply\(\)\`. In library code, use \`asyncio.get\_running\_loop\(\)\` instead of creating a new one.
Journey Context:
You paste a snippet using \`asyncio.run\(main\(\)\)\` into a Jupyter notebook cell and it raises \`RuntimeError: This event loop is already running\`. You try wrapping it in \`asyncio.new\_event\_loop\(\).run\_until\_complete\(...\)\` and get \`RuntimeError: Event loop already running\`. The notebook kernel already maintains a single event loop per kernel process; \`asyncio.run\(\)\` is designed to create, run, and close a new loop, which conflicts with the running one. Awaiting the coroutine directly in the cell works because it runs inside the existing loop. When you need to call async code from synchronous notebook callbacks, \`nest\_asyncio\` patches the loop to allow re-entrant execution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:39:28.211287+00:00— report_created — created