# asyncio异常：睡眠被中断

- **ID:** `python/asyncio-sleep-interrupt`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在asyncio.sleep()期间任务被取消，这是一个常见的取消点。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.7 | active | — | — |
| 3.8 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   try: await asyncio.sleep(10) except asyncio.CancelledError: raise
   ```
2. **** (80% 成功率)
   ```
   await asyncio.shield(asyncio.sleep(10))
   ```

## 无效尝试

- **** — Blocks the event loop and defeats the purpose of asyncio. (90% 失败率)
- **** — May lead to resource leaks and inconsistent state. (70% 失败率)
