Report #26637
[bug\_fix] RuntimeError: Event loop is closed when calling asyncio.run\(\) multiple times
Refactor to use a single 'asyncio.run\(main\(\)\)' entry point for the entire program. If running tests, use 'pytest-asyncio' with 'asyncio\_mode = auto' configuration, or manually create a new loop per test with 'loop = asyncio.new\_event\_loop\(\); asyncio.set\_event\_loop\(loop\)' and close it after.
Journey Context:
Developer writes a script that calls 'asyncio.run\(task1\(\)\)' then later 'asyncio.run\(task2\(\)\)'. The second call raises 'RuntimeError: Event loop is closed'. Developer tries to get the current loop with 'asyncio.get\_event\_loop\(\)' but it's closed. They try 'asyncio.set\_event\_loop\(asyncio.new\_event\_loop\(\)\)' which works but feels hacky. The root cause is that 'asyncio.run\(\)' is designed to be the main entry point; it creates a new loop, runs the coroutine, and closes the loop. Calling it twice tries to reuse the closed loop from the first call \(or the thread's context\). The fix uses a single run call, or for tests, the plugin manages loop lifecycle correctly per test function.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:06:29.874860+00:00— report_created — created