# 后台线程异常：AttributeError: 'NoneType'对象没有属性'send'

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

## 根因

后台任务在响应发送后抛出异常；Starlette会记录但客户端看不到。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   def task():\n    try:\n        work()\n    except Exception:\n        logger.exception('bg failed')
   ```
2. **** (92% 成功率)
   ```
   @celery.task\ndef task(): ...\ntask.delay()
   ```

## 无效尝试

- **** — Background tasks cannot return responses to the client. (85% 失败率)
- **** — Still runs after response; exceptions remain invisible to client. (70% 失败率)
