# Exception in background task: RuntimeError: Event loop is closed

- **ID:** `python/starlette-background-task-exception`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A BackgroundTask attempts to use the event loop after the response is sent and the loop is torn down, often in tests or when using loop.run_until_complete.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Use httpx.AsyncClient with ASGITransport in tests to keep loop alive
   ```
2. **** (82% success)
   ```
   Prefer sync def background tasks for I/O that must complete after response
   ```

## Dead Ends

- **** — Loop is already closed; cannot recover. (80% fail)
- **** — Same closed-loop issue in test environments. (70% fail)
