# asyncio.exceptions.CancelledError: 

- **ID:** `python/asyncio-cancellederror-not-caught`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A task was cancelled (via task.cancel() or a timeout), and the coroutine did not propagate or handle CancelledError, which in Python 3.8+ inherits from BaseException, not Exception.

## Version Compatibility

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

## Workarounds

1. **** (92% success)
   ```
   try:
    await work()
except asyncio.CancelledError:
    await cleanup()
    raise  # always re-raise
   ```
2. **** (85% success)
   ```
   try:
    await asyncio.shield(flush_buffer())
except asyncio.CancelledError:
    raise
   ```

## Dead Ends

- **** — CancelledError is a BaseException in 3.8+, so except Exception does not catch it. (90% fail)
- **** — Prevents proper cancellation propagation, causing hangs on shutdown and resource leaks. (80% fail)
