{
  "id": "python/asyncio-queue-task-done-never-set",
  "signature": "asyncio.exceptions.InvalidStateError: Task is not done",
  "signature_zh": "asyncio.exceptions.InvalidStateError: 任务尚未完成",
  "regex": "asyncio\\.exceptions\\.InvalidStateError:\\ Task\\ is\\ not\\ done",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "task.result() or task.exception() was called before the task completed; both require the task to be in the DONE state.",
  "root_cause_type": "generic",
  "root_cause_zh": "在任务完成之前调用了 task.result() 或 task.exception()，二者都要求任务处于 DONE 状态。",
  "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": "Arbitrary sleeps are racy; under load the task may still be pending.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Busy-looping until done wastes CPU and does not guarantee completion.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "task = asyncio.create_task(work())\nresult = await task",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "done, pending = await asyncio.wait({task}, timeout=10)\nif task in done:\n    print(task.result())",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-04",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}