python
runtime_error
ai_generated
true
asyncio.exceptions.CancelledError: sleep interrupted
ID: python/asyncio-sleep-interrupt
80%Fix Rate
87%Confidence
0Evidence
2025-05-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
Root Cause
A task is cancelled during asyncio.sleep(), which is a common cancellation point.
generic中文
在asyncio.sleep()期间任务被取消,这是一个常见的取消点。
Workarounds
-
95% success
try: await asyncio.sleep(10) except asyncio.CancelledError: raise
-
80% success
await asyncio.shield(asyncio.sleep(10))
Dead Ends
Common approaches that don't work:
-
90% fail
Blocks the event loop and defeats the purpose of asyncio.
-
70% fail
May lead to resource leaks and inconsistent state.