Forums

Can Flask show user status reports while looping through a long python function?

I'm working on a Flask python web app that takes a file upload and processes it. The processing can take several minutes as it iterates through each row of a large dataframe. I'd like to show the user what row is being processed or at least when every x rows have been processed. I haven't been able to get either flash messages or rendering templates to work to show the status information. Is it possible to provide the user with the kind of status updates I am looking for?

Try looking into pusher. You could get your process to push out an update/notification every n rows etc.

On the other hand, if it's many minutes, you run the risk that your http connection will get broken and the code that you have running will get interrupted/exited. On PythonAnywhere, any connections >5min will get cut off.