python
runtime_error
ai_generated
true
concurrent.futures.CancelledError: Future was cancelled
ID: python/asyncio-cancel-future
80%Fix Rate
83%Confidence
0Evidence
2024-11-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
Root Cause
Awaiting a future that has been cancelled, often due to a parent task being cancelled.
generic中文
等待一个已被取消的future,通常是因为父任务被取消。
Workarounds
-
90% success
if not fut.cancelled(): await fut
-
95% success
try: await fut except asyncio.CancelledError: raise
Dead Ends
Common approaches that don't work:
-
70% fail
Swallowing cancellation can lead to inconsistent state and resource leaks.
-
80% fail
result() raises the same error; it's not a proper fix.