{
  "id": "python/asyncio-cancellederror-not-caught",
  "signature": "asyncio.exceptions.CancelledError: ",
  "signature_zh": "asyncio.exceptions.CancelledError: ",
  "regex": "asyncio\\.exceptions\\.CancelledError:\\ ",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "任务被取消（通过 task.cancel() 或超时），而协程未传播或处理 CancelledError；在 Python 3.8+ 中它继承自 BaseException 而非 Exception。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "CancelledError is a BaseException in 3.8+, so except Exception does not catch it.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Prevents proper cancellation propagation, causing hangs on shutdown and resource leaks.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "try:\n    await work()\nexcept asyncio.CancelledError:\n    await cleanup()\n    raise  # always re-raise",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "try:\n    await asyncio.shield(flush_buffer())\nexcept asyncio.CancelledError:\n    raise",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-21",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}