# RuntimeError: Background task failed: 'NoneType' object has no attribute 'send'

- **ID:** `python/starlette-background-task-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A background task function is not defined as async or is called incorrectly, causing the ASGI server to fail when trying to run it.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Define the task as async: async def send_email(email: str):\n    # ...\nthen use BackgroundTask(send_email, email)
   ```
2. **** (90% success)
   ```
   Use Starlette's BackgroundTasks: background_tasks.add_task(send_email, email)
   ```

## Dead Ends

- **** — Calling the background task function directly instead of passing it to BackgroundTask causes immediate execution. (80% fail)
- **** — Making the task synchronous works in some cases but blocks the event loop. (60% fail)
