'Flask: send information back to browser while processing time consuming process
I am using Flask with Python 3.9 on Linux, using nginx and uWSGI.
SITUATION
One of the pages a user can choose will require 35+ API calls to other IP devices, responding in various speed, which means the page will take at least 30~40 seconds to display. It is frustrating for many users who sometimes think the page has become unresponsive.
So far I am displaying an animated GIF to make the user wait, but I really would like to provide information as far as where the process is at, until the final result is displayed.
In the route code, I print some debug information (Calling API XYZ... Processed Results... Calling API EXP.. Processing results... etc.) and I wish I could send exactly that to the browser while the user waits. Users would know exactly what is happening and where the process is at.
Once all API data is received, some calculations are done, data is organized in dictionaries and sent to Jinga2 for display.
QUESTION
How can I send strings of characters throughout the process of a Flask route back to the browser, until the final result is ready to render_template?
I am guessing websockets is one of them? If you could provide or point to a sample, it would be very much appreciated.
Thank you so much for your time and your help to the community!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
