Report #10810
[bug\_fix] RuntimeError: This event loop is already running
In Jupyter, use 'await main\(\)' directly instead of 'asyncio.run\(\)', or install and apply 'nest\_asyncio' to patch the loop.
Journey Context:
Developer writes an async function and tries to run it in a Jupyter notebook cell using 'asyncio.run\(main\(\)\)'. They immediately get 'RuntimeError: This event loop is already running'. Confused because the identical code works in a standalone .py file. They try to get the current loop with 'asyncio.get\_event\_loop\(\)' but running it still fails. They realize that Jupyter/IPython already has an asyncio event loop running in the main kernel thread to handle async cell execution and interactivity. The fix is to use 'await main\(\)' directly in the notebook cell \(since Jupyter cells can be async and automatically await coroutines\), or to install and apply 'nest\_asyncio' which patches asyncio to allow nested loops, enabling 'asyncio.run\(\)' to work inside the existing loop by temporarily suspending the outer loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:44:36.443033+00:00— report_created — created