# DeprecationWarning: 没有当前事件循环

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

## 根因

在没有运行循环且当前线程未设置循环的情况下调用了 asyncio.get_event_loop()；Python 3.10+ 弃用此行为，3.12+ 发出警告。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Inside async code, use asyncio.get_running_loop():

loop = asyncio.get_running_loop()
   ```
2. **** (90% 成功率)
   ```
   From sync code, use asyncio.new_event_loop() and manage lifetime explicitly:

loop = asyncio.new_event_loop()
try:
    loop.run_until_complete(coro())
finally:
    loop.close()
   ```
3. **** (92% 成功率)
   ```
   Use asyncio.Runner (3.11+) for repeated runs:

with asyncio.Runner() as runner:
    runner.run(coro())
   ```

## 无效尝试

- **** — Hides the warning but the underlying API will be removed in 3.14. (70% 失败率)
- **** — Creates a loop that is never closed; leaks resources and causes 'loop is closed' errors later. (65% 失败率)
- **** — Not a maintainable fix; 3.9 is EOL in Oct 2025. (90% 失败率)
