Flask: asynchronous response to client Flask: asynchronous response to client flask flask

Flask: asynchronous response to client


What you ask cannot be done with the HTTP protocol. Each request receives a response synchronously. The closest thing to achieve what you want would be this:

The client sends the request and the server responds with a job id immediately, while it also starts a background task for this long calculation.

The client can then poll the server for status by sending the job id in a new request. The response is again immediate and contains a job status, such as "in progress", "completed", "failed", etc. The server can also return a progress percentage, which the client can use to render a progress bar.

You could also implement web sockets, but that will require socket enabled server and client.