{
  "id": "python/asyncio-cancellederror-not-handled",
  "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 (timeout, shutdown, or parent cancellation) and the CancelledError propagated uncaught, often logged as an unhandled task exception.",
  "root_cause_type": "generic",
  "root_cause_zh": "某个任务被取消（超时、关闭或父任务取消），CancelledError 未被捕获并传播，通常被记录为未处理的任务异常。",
  "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": "Swallowing cancellation breaks structured concurrency; the parent expects the task to stop.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Shield everywhere defeats cancellation and leaves tasks running after shutdown.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "try:\n    await long_running()\nexcept asyncio.CancelledError:\n    await cleanup()\n    raise",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "tasks = [asyncio.create_task(w(i)) for i in range(5)]\ntry:\n    await asyncio.gather(*tasks)\nexcept asyncio.CancelledError:\n    for t in tasks:\n        t.cancel()\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.86,
  "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": []
}