# WARNING: 在异步端点中检测到阻塞调用: time.sleep(5)

- **ID:** `python/fastapi-event-loop-blocking-call`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 async def 端点中直接调用了同步阻塞函数（time.sleep、requests、CPU 密集型工作），冻结了事件循环。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.9+ | active | — | — |
| 3.10+ | active | — | — |
| 3.11+ | active | — | — |
| 3.12+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   from fastapi.concurrency import run_in_threadpool

@app.get('/x')
async def x():
    result = await run_in_threadpool(blocking_fn, arg)
   ```
2. **** (93% 成功率)
   ```
   async with httpx.AsyncClient() as client:
    r = await client.get(url)
   ```

## 无效尝试

- **** — Each worker still blocks its own loop; throughput does not improve for a single request. (75% 失败率)
- **** — Yielding once does not prevent the subsequent block from stalling the loop. (80% 失败率)
