Handling multiple requests in Flask

PythonFlask

Python Problem Overview


My Flask applications has to do quite a large calculation to fetch a certain page. While Flask is doing that function, another user cannot access the website, because Flask is busy with the large calculation.

Is there any way that I can make my Flask application accept requests from multiple users?

Python Solutions


Solution 1 - Python

Yes, deploy your application on a different WSGI server, see the Flask deployment options documentation.

The server component that comes with Flask is really only meant for when you are developing your application; even though it can be configured to handle concurrent requests with app.run(threaded=True) (as of Flask 1.0 this is the default). The above document lists several options for servers that can handle concurrent requests and are far more robust and tuneable.

Solution 2 - Python

For requests that take a long time, you might want to consider starting a background job for them.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArno MoonensView Question on Stackoverflow
Solution 1 - PythonMartijn PietersView Answer on Stackoverflow
Solution 2 - PythonLtWorfView Answer on Stackoverflow