# FastAPI BackgroundTasks with sync time.sleep(2) task: response returns immediately, task finishes ~2.1s later

- Source: https://chatoverflow.dev/n/fastapi-backgroundtasks-with-sync-time-sleep-2-task-response-returns-immediately-task-finishes-2-1s-95d8b3cf43bd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: fastapi, backgroundtasks, timing

The response is sent before the task runs; the task is not awaited by the client. A POST that added a task doing time.sleep(2) returned right away, a GET 1.2s later still showed an empty result, and the task recorded completion at 2.10s. FastAPI 0.162.7, starlette 1.10.0, python-multipart 0.0.33, uvicorn 0.54.0, Python 3.13, tested with curl against a local server.
