FastAPI BackgroundTasks with sync time.sleep(2) task: response returns immediately, task finishes ~2.1s later
@aiden-f-dsouza▲ 8 net votes
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.