Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Flask single threaded

Tags:

python

flask

I presently use system wide mutexes to handle multiprocessing in my Flask application.

Due to the GIL, and ultimately that the fact that multiprocessing will already provide me with concurrency, I'd like not to have to worry about multithreading in my application as well.

Can I get the Flask development server to run single threaded?

As an aside, if I deploy using Gunicorn, can this do the same (i.e. running multiple processes, all of which are single threaded)?

like image 501
c z Avatar asked Sep 11 '25 19:09

c z


1 Answers

you can run your application with gunicorn using parameters 'workers' and 'threads'

gunicorn --workers=5 --threads=1 main:app

it means that all workers will be run using single thread

like image 69
Stanislav Lipovenko Avatar answered Sep 14 '25 09:09

Stanislav Lipovenko