# asyncio.exceptions.CancelledError

- **ID:** `python/asyncio-cancel-error-on-shutdown`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Task cancellation during shutdown causes unhandled CancelledError in finally blocks that await cleanup operations.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.11 | active | — | — |

## Workarounds

1. **** (85% success)
   ```
   await asyncio.shield(cleanup()) within finally to protect cleanup from cancellation
   ```
2. **** (90% success)
   ```
   asyncio.run(main()) handles cancellation gracefully by cancelling all remaining tasks
   ```

## Dead Ends

- **** —  (70% fail)
- **** —  (60% fail)
