# RuntimeError: 无法从正在运行的事件循环中调用 asyncio.run()

- **ID:** `python/starlette-loop-already-running`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

同步的 FastAPI/Starlette 路由或依赖项在服务器事件循环已运行时调用了 asyncio.run()。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.27+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   @app.get('/x')
async def handler():
    return await some_coroutine()
   ```
2. **** (75% 成功率)
   ```
   import anyio
result = anyio.from_thread.run(some_coroutine)
   ```

## 无效尝试

- **** — Patches the loop but breaks uvicorn's task scheduling and can deadlock under load. (70% 失败率)
- **** — Raises 'This event loop is already running' since the loop cannot be re-entered. (85% 失败率)
