Report #88410
[bug\_fix] RuntimeError: asyncio.run\(\) cannot be called from a running event loop
In interactive environments \(Jupyter, IPython\), use \`await my\_coroutine\(\)\` directly instead of \`asyncio.run\(\)\`. For scripts that must run in both sync and async contexts, use \`nest\_asyncio.apply\(\)\` to patch the running loop, or refactor to use the lower-level \`loop.create\_task\(\)\` if already inside an async def.
Journey Context:
Developer writes an async main function and wants to test it quickly in a Jupyter notebook cell. They write \`asyncio.run\(main\(\)\)\` and execute the cell, immediately triggering a RuntimeError stating the loop is already running. They inspect \`asyncio.get\_event\_loop\(\)\` and see it is indeed running \(the kernel uses it\). They try \`loop.run\_until\_complete\(main\(\)\)\` but get deprecation warnings or similar errors. After searching, they find that Jupyter kernels \(via IPython\) already manage an event loop and \`asyncio.run\` tries to create a new one, which is prohibited. The correct pattern in notebooks is to simply \`await main\(\)\` directly in a cell because the cell execution context is already async. Alternatively, \`import nest\_asyncio; nest\_asyncio.apply\(\)\` patches the standard library to allow nested loops, which is useful for running library code that uses \`asyncio.run\` internally.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:58:52.967212+00:00— report_created — created