{
  "id": "python/fastapi-event-loop-blocking-call",
  "signature": "WARNING:  Blocking call detected in async endpoint: time.sleep(5)",
  "signature_zh": "WARNING: 在异步端点中检测到阻塞调用: time.sleep(5)",
  "regex": "WARNING:\\ \\ Blocking\\ call\\ detected\\ in\\ async\\ endpoint:\\ time\\.sleep\\(5\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A synchronous blocking function (time.sleep, requests, CPU-bound work) was called directly inside an async def endpoint, freezing the event loop.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 async def 端点中直接调用了同步阻塞函数（time.sleep、requests、CPU 密集型工作），冻结了事件循环。",
  "versions": [
    {
      "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": "Each worker still blocks its own loop; throughput does not improve for a single request.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Yielding once does not prevent the subsequent block from stalling the loop.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from fastapi.concurrency import run_in_threadpool\n\n@app.get('/x')\nasync def x():\n    result = await run_in_threadpool(blocking_fn, arg)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "async with httpx.AsyncClient() as client:\n    r = await client.get(url)",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}