# RuntimeError: Event loop is closed

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

## Root Cause

Async resources (httpx.AsyncClient, aiohttp session) created in one event loop are reused after that loop closed, common in tests or reload.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Create clients inside lifespan and close on shutdown:
@asynccontextmanager
async def lifespan(app):
    app.state.client = httpx.AsyncClient()
    yield
    await app.state.client.aclose()
   ```
2. **** (85% success)
   ```
   Use pytest-asyncio with a single loop fixture for tests.
   ```

## Dead Ends

- **** — Creates a fresh loop but existing clients bound to the old loop still fail. (75% fail)
- **** — Subsequent requests hang or raise again on the closed loop. (80% fail)
