# RuntimeError: 此事件循环已在运行

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

## 根因

在已经运行的事件循环内部调用了 asyncio.run() 或 loop.run_until_complete()，例如在 Jupyter notebook、异步函数或已持有循环的框架中。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   import nest_asyncio
nest_asyncio.apply()
asyncio.run(main())
   ```
2. **** (95% 成功率)
   ```
   async def outer():
    await main()  # instead of asyncio.run(main())
   ```

## 无效尝试

- **** — Stopping the loop corrupts the outer framework's scheduling and causes pending tasks to hang. (85% 失败率)
- **** — Creates a nested loop that cannot await futures belonging to the outer loop; raises 'attached to a different loop'. (70% 失败率)
