# RuntimeWarning: 协程 'send_email' 从未被 await。

- **ID:** `python/fastapi-background-task-not-awaited`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

将异步函数传给 BackgroundTasks.add_task 而未 await；或在同步路由中直接调用异步函数而未调度。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.100.x | active | — | — |
| 0.110.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   In async route: `background_tasks.add_task(send_email, to, body)` — FastAPI awaits it after response.
   ```
2. **** (85% 成功率)
   ```
   For sync routes, use a sync function or `asyncio.run(send_email(...))` (careful with loops) or offload to Celery.
   ```

## 无效尝试

- **** — Task may be cancelled when request ends; not tracked by FastAPI. (80% 失败率)
- **** — Requires a running event loop and proper thread context; often raises RuntimeError. (75% 失败率)
