# RuntimeError: Event loop is closed

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

## Root Cause

Async resources (e.g., aiohttp/httpx client, DB pool) created in one event loop are reused after that loop is closed, often across test cases or reloads.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 0.30+ | active | — | — |

## Workarounds

1. **** (92% success)
   ```
   from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app):
    app.state.client = httpx.AsyncClient()
    yield
    await app.state.client.aclose()
app = FastAPI(lifespan=lifespan)
   ```
2. **** (90% success)
   ```
   async with httpx.AsyncClient() as client:
    r = await client.get(url)
   ```

## Dead Ends

- **** — Replaces loop but leaves stale client bound to old loop. (80% fail)
- **** — Buffering setting irrelevant to event loop lifecycle. (95% fail)
