# RuntimeWarning: 协程 'fetch_data' 从未被 await

- **ID:** `python/coroutine-never-awaited`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

调用了一个协程函数但没有 await 或 asyncio.create_task，因此创建了协程对象并在未运行的情况下被垃圾回收。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Await the coroutine in an async context:

async def main():
    data = await fetch_data()
   ```
2. **** (90% 成功率)
   ```
   If you intentionally want fire-and-forget, schedule it:

asyncio.create_task(fetch_data())
   ```
3. **** (88% 成功率)
   ```
   Enable -W error::RuntimeWarning in tests to catch this at CI time.
   ```

## 无效尝试

- **** — Hides the symptom; the async work silently never runs. (90% 失败率)
- **** — Raises 'asyncio.run() cannot be called from a running event loop'. (85% 失败率)
- **** — Breaks other callers and loses concurrency. (70% 失败率)
