Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Flask, parallel requests

Tags:

python

flask

wsgi

When I test my new Flask application with the built in web server, everything is "single threaded" and blocking. The server can not serve one request without finishing another. It can only process one request at a time.

When deploying a web service, this is obviously not desirable. How do you deploy Flask applications so that things can move in parallel?

Are there different things to consider regarding thread safety and concurrency inside the code (protect objects with locks and so on) or are all the offerings equivalent?

like image 930
Prof. Falken Avatar asked Sep 27 '12 11:09

Prof. Falken


2 Answers

I use uWSGI with the gevent loop. That is the ticket. In fact, this is how I use py-redis which is blocking to not be blocking.

Also, I use uWSGI to write requests after the response while still accepting more requests.

like image 137
Tampa Avatar answered Sep 27 '22 20:09

Tampa


There are a number of good options. I think the two most popular are probably:

Running it behind Apache with mod_wsgi or behind Nginx with uWsgi

Both of these have worked well for me.

like image 33
damzam Avatar answered Sep 27 '22 22:09

damzam