How to run Flask with Gunicorn in multithreaded mode

You can start your app with multiple workers or async workers with Gunicorn.

Flask server.py

from flask import Flask
app = Flask(__name__)

@app.route("https://stackoverflow.com/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

Gunicorn with gevent async worker

gunicorn server:app -k gevent --worker-connections 1000

Gunicorn 1 worker 12 threads:

gunicorn server:app -w 1 --threads 12

Gunicorn with 4 workers (multiprocessing):

gunicorn server:app -w 4

More information on Flask concurrency in this post: How many concurrent requests does a single Flask process receive?.

Leave a Comment