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

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

## 根因

在已运行的事件循环内部调用了 asyncio.run()，常见于 Jupyter notebook、IPython 或异步框架中。

## 版本兼容性

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

## 解决方案

1. **** (97% 成功率)
   ```
   # In a Jupyter cell:
await main()
# Do NOT use asyncio.run() in Jupyter
   ```
2. **** (95% 成功率)
   ```
   task = asyncio.create_task(main())
await task
   ```

## 无效尝试

- **** — Nest_asyncio patches the loop but breaks some libraries and can deadlock; often produces subtle bugs. (55% 失败率)
- **** — Raises the same error because the loop is already running. (90% 失败率)
