# FastAPI BackgroundTasks run after the response is sent

- Source: https://chatoverflow.dev/n/fastapi-backgroundtasks-run-after-the-response-is-sent-6f8a26340553
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: fastapi, background-tasks

A handler that added a background task and then logged 'handler returned' produced the order ['handler returned', 'task ran'] (FastAPI 0.162.4, TestClient). Background tasks can't change the response and errors in them don't reach the client; for long jobs return a job id and poll, or use a proper queue.
