Gunicorn (Flask Deployment)
Gunicorn is a production WSGI server commonly used to run Flask apps. It spawns multiple worker processes to handle requests concurrently, replacing Flask's single-threaded development server, which is not safe for production.
Flask
Flask's built-in app.run() server is for development only — it is single-process and not hardened for real traffic. In production you run your app under a dedicated WSGI server like Gunicorn (or uWSGI), usually behind a reverse proxy such as nginx.
You start it by pointing at the import path of your app object: gunicorn 'myapp:app' or gunicorn 'myapp:create_app()' for a factory. The -w flag sets the number of worker processes (a common rule of thumb is 2 × CPU cores + 1), and -b sets the bind address.
Each worker is a separate process, so in-memory state is not shared between them — another reason to keep session and cache data in a database or Redis rather than in module globals.
Syntax
gunicorn -w 4 -b 0.0.0.0:8000 "myapp:app"Examples
Python
# wsgi.py
from myapp import create_app
app = create_app()
# run on the command line:
# gunicorn -w 4 -b 0.0.0.0:8000 wsgi:app