# RuntimeError: Event loop is closed

- **ID:** `python/asyncio-event-loop-closed`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to use an asyncio event loop after it has been explicitly closed, often due to calling loop.close() prematurely or reusing a loop after shutdown.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |

## Workarounds

1. **Use asyncio.run() for top-level entry point to avoid manual loop management** (95% success)
   ```
   async def main(): await some_coroutine(); asyncio.run(main())
   ```
2. **Check if loop is closed before using it, and create a new one if needed** (85% success)
   ```
   if loop.is_closed(): loop = asyncio.new_event_loop(); asyncio.set_event_loop(loop)
   ```

## Dead Ends

- **Recreating the loop with asyncio.new_event_loop() without setting it as current** — The new loop is not set as the current loop, so asyncio.get_event_loop() still returns a closed loop. (70% fail)
- **Ignoring the error and continuing execution** — The closed loop cannot process coroutines, leading to hangs or crashes later. (90% fail)
- **Using loop.run_forever() after loop.close()** — A closed loop cannot be restarted; run_forever() raises RuntimeError. (100% fail)
