# RuntimeError: Event loop is closed

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

## Root Cause

An asyncio coroutine or aiohttp session is reused after the event loop that created it has been closed. Common when calling asyncio.run() multiple times, or when a ClientSession is created outside the loop and used inside a different asyncio.run() call. The underlying transport/socket is bound to a now-dead loop.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8+ | active | — | — |
| 3.10+ | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   async def main():
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as r:
            return await r.text()

asyncio.run(main())  # session lives and dies inside this loop
   ```
2. **** (85% success)
   ```
   import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
    loop.run_until_complete(main())
finally:
    loop.run_until_complete(loop.shutdown_asyncgens())
    loop.close()
   ```

## Dead Ends

- **** — Silencing the exception leaves the coroutine unfinished and leaks resources; the next call fails differently or hangs. (90% fail)
- **** — A closed loop cannot be restarted; run_until_complete raises RuntimeError immediately. (95% fail)
- **** — Policy changes do not resurrect a closed loop; the error is lifecycle, not platform. (85% fail)
