Reputation: 9027
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)?
Upvotes: 4
Views: 3255
Reputation: 9027
After looking at the source code, I see that Flask has the --without-threads
parameter, which was added as a result of this bug report.
. . .
flask run --without-threads . . .
As far as I can tell it doesn't appear that the Flask documentation has been updated as a result of the bug fix, so the best documentation can be found in the bug report itself. You can query this property at run-time via flask.request.is_multithread
.
Upvotes: 3
Reputation: 4446
The flask development server is only single-threaded by default, and yes you can use unicorn with the workers
and thread
flags
gunicorn --workers=8 --threads=1
Upvotes: 2
Reputation: 574
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
Upvotes: 7