Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling multiple requests in Flask

Tags:

python

flask

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?

like image 305
Arno Moonens Avatar asked Feb 03 '13 13:02

Arno Moonens


People also ask

Can Flask handle multiple requests?

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).

How many requests can Flask handle at once?

Flask will process one request per thread at the same time. If you have 2 processes with 4 threads each, that's 8 concurrent requests.

How do you handle requests in Flask?

Any flask application, while handling a request, creates a Request object. This object created is dependent on the environment as received by the WSGI server. A worker is able to handle only one request at a time. As the request is made, the flask application automatically pushes a request context during the course.

Are Python flasks multithreaded?

As of Flask 1.0, flask server is multi-threaded by default. Each new request is handled in a new thread. This is a simple Flask application using default settings.


1 Answers

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.

like image 119
Martijn Pieters Avatar answered Sep 29 '22 22:09

Martijn Pieters