# RuntimeWarning: 协程 'sleep' 从未被等待 / requests.exceptions.ConnectionError: ('连接中止。', RemoteDisconnected('远程端关闭连接而未响应'))

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

## 根因

在 async def 端点内进行阻塞式同步调用（requests、time.sleep、重 IO）会阻塞事件循环，导致超时和连接中断。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   import httpx
async with httpx.AsyncClient() as client:
    r = await client.get(url)
   ```
2. **** (90% 成功率)
   ```
   from starlette.concurrency import run_in_threadpool
result = await run_in_threadpool(blocking_fn, arg)
   ```

## 无效尝试

- **** — Does not unblock the event loop; requests still queue. (80% 失败率)
- **** — Each worker still has one blocked loop; capacity is limited. (70% 失败率)
