Report #96461
[bug\_fix] RuntimeError: Cannot run the event loop while another loop is running
In Jupyter/IPython, use \`await main\(\)\` directly instead of \`asyncio.run\(main\(\)\)\`, or apply \`nest\_asyncio\` to allow nested loops.
Journey Context:
Developer writes an async application with \`async def main\(\): ...\` and tries to run it in a Jupyter notebook cell using \`asyncio.run\(main\(\)\)\`. Jupyter kernels already run an event loop in the background thread to handle kernel I/O and widget updates. \`asyncio.run\(\)\` attempts to create a new event loop and run it, but detects the existing running loop and raises RuntimeError. Developer tries \`loop = asyncio.get\_event\_loop\(\); loop.run\_until\_complete\(main\(\)\)\` but gets the same error because \`get\_event\_loop\(\)\` returns the running loop. The fix works because in an async context like Jupyter, \`await main\(\)\` directly leverages the existing running event loop without trying to start a new one, allowing the coroutine to schedule itself on the existing loop and execute immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:29:42.116430+00:00— report_created — created