Report #14188
[bug\_fix] RuntimeError: no running event loop / RuntimeError: Event loop is closed
Use \`asyncio.run\(\)\` exactly once as the entry point; for nested async calls, use \`await\` directly. In Jupyter/IPython, use \`await\` directly in a cell or apply \`nest\_asyncio\` patch.
Journey Context:
Developer writes a script that calls \`asyncio.run\(main\(\)\)\` at the bottom. Inside \`main\(\)\`, they call a library function that internally uses \`asyncio.run\(\)\` again \(or they try to call \`asyncio.get\_running\_loop\(\)\` outside any async context\). This raises \`RuntimeError: no running event loop\`. Alternatively, in a Jupyter notebook, they run a cell that creates a loop with \`loop = asyncio.get\_event\_loop\(\)\`, then close it, then run another cell that tries to use the closed loop, getting \`Event loop is closed\`. The confusion stems from asyncio's strict policy: \`asyncio.run\(\)\` creates a new loop, runs the coroutine, and closes the loop. It cannot be called recursively. The fix is to refactor so that \`asyncio.run\(\)\` is called exactly once at the entry point, and everywhere else uses \`await\`. In Jupyter, since the kernel already runs a loop, use \`await func\(\)\` directly in a cell, or install \`nest\_asyncio\` to allow nested \`asyncio.run\(\)\` calls for quick testing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:51:12.863750+00:00— report_created — created