{
  "id": "python/fastapi-async-route-blocking-event-loop",
  "signature": "WARNING:  (tracemalloc) ... asyncio: Task was destroyed but it is pending!\nBlocking call detected in async def route, event loop stalled for 5.2s",
  "signature_zh": "警告：事件循环被阻塞，异步路由中检测到阻塞调用，事件循环停滞 5.2 秒。",
  "regex": "WARNING:\\ \\ \\(tracemalloc\\)\\ \\.\\.\\.\\ asyncio:\\ Task\\ was\\ destroyed\\ but\\ it\\ is\\ pending!\\\nBlocking\\ call\\ detected\\ in\\ async\\ def\\ route,\\ event\\ loop\\ stalled\\ for\\ 5\\.2s",
  "domain": "python",
  "category": "system_error",
  "subcategory": null,
  "root_cause": "An `async def` route calls a synchronous/blocking function (requests, time.sleep, heavy CPU) directly, freezing the event loop.",
  "root_cause_type": "generic",
  "root_cause_zh": "`async def` 路由直接调用了同步/阻塞函数（requests、time.sleep、重 CPU 操作），冻结了事件循环。",
  "versions": [
    {
      "version": "0.100.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "0.110.x",
      "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 under load.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Does not yield for blocking I/O; loop still stalls.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Use httpx.AsyncClient: `async with httpx.AsyncClient() as c: r = await c.get(url)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Offload with `await asyncio.to_thread(blocking_fn, args)` or `run_in_executor`.",
      "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": "2025-05-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}