{
  "id": "python/asyncio-timeout-no-current-event-loop",
  "signature": "RuntimeError: Timeout context manager should be used inside a task",
  "signature_zh": "RuntimeError: 超时上下文管理器应在任务内部使用",
  "regex": "RuntimeError:\\ Timeout\\ context\\ manager\\ should\\ be\\ used\\ inside\\ a\\ task",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "asyncio.timeout() (3.11+) or asyncio.wait_for() was used outside a Task context, e.g. directly in loop.run_until_complete() without wrapping in create_task.",
  "root_cause_type": "generic",
  "root_cause_zh": "asyncio.timeout()（3.11+）或 asyncio.wait_for() 在 Task 上下文之外使用，例如直接在 loop.run_until_complete() 中调用而未用 create_task 包装。",
  "versions": [
    {
      "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": "Blocks the loop and defeats async concurrency.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Debug flag is unrelated; the check is unconditional.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "task = asyncio.create_task(do_work())\ntry:\n    async with asyncio.timeout(5):\n        await task\nexcept TimeoutError:\n    task.cancel()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "try:\n    result = await asyncio.wait_for(do_work(), timeout=5)\nexcept asyncio.TimeoutError:\n    ...",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}