{
  "id": "python/asyncio-sleep-blocks-loop",
  "signature": "RuntimeWarning: coroutine 'sleep' was never awaited — did you mean time.sleep?",
  "signature_zh": "RuntimeWarning: 协程 'sleep' 从未被 await —— 你是想用 time.sleep 吗？",
  "regex": "RuntimeWarning:\\ coroutine\\ 'sleep'\\ was\\ never\\ awaited\\ —\\ did\\ you\\ mean\\ time\\.sleep\\?",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "time.sleep() was called inside an async function, blocking the entire event loop instead of yielding control.",
  "root_cause_type": "generic",
  "root_cause_zh": "在异步函数中调用了 time.sleep()，阻塞了整个事件循环，而不是让出控制权。",
  "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": "Still blocks the loop, just for less time.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Works but wastes a thread for what asyncio.sleep does natively.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Overcomplicated; the blocking call still stalls that thread's loop.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "Use asyncio.sleep:\n\nimport asyncio\nawait asyncio.sleep(1)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "For CPU-bound work, offload to a thread:\n\nawait asyncio.to_thread(cpu_heavy_fn)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Enable asyncio debug mode to catch blocking calls:\n\nasyncio.run(main(), debug=True)",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-28",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}