# RuntimeError: 任务获取了附加到不同事件循环的 Future

- **ID:** `python/asyncio-task-got-future-different-loop`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在某个事件循环下创建的协程或 Future 被另一个循环 await，例如两次调用 asyncio.run() 或混用 loop.run_until_complete() 与 asyncio.run()。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())  # single entry point
   ```
2. **** (90% 成功率)
   ```
   # In Jupyter/IPython or uvicorn, just 'await main()'
# Do NOT call asyncio.run() inside an already-running loop
   ```

## 无效尝试

- **** — The Future object still references the original loop; identity mismatch remains. (85% 失败率)
- **** — ensure_future still binds to the current loop, not the Future's original loop. (80% 失败率)
