Run Flask Under Gunicorn
Serve the app with multiple workers.
Run Flask Under Gunicorn is a free Flask Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Gunicorn Is
Gunicorn is a production WSGI server for Python. It runs your Flask app across multiple worker processes so many users can be served at once. 🦄
Install It
Add Gunicorn to your environment with pip. Treat it as a real dependency and pin it in your requirements file.
pip install gunicornIt Needs Your App Object
Gunicorn must find the WSGI callable. That is the Flask app instance you created, usually named app in your module.
# app.py
from flask import Flask
app = Flask(__name__)The module:variable Pattern
You point Gunicorn at your app using module:variable syntax. The part before the colon is the file, the part after is the app name.
gunicorn app:appA Clean wsgi.py Entry Point
Many teams add a tiny wsgi.py that just exposes the app. It keeps the run command stable even as the app grows.
# wsgi.py
from app import app
# gunicorn wsgi:appChoosing the Worker Count
The --workers flag sets how many processes handle requests. A common starting point is two times your CPU cores plus one.
gunicorn --workers 3 wsgi:appBinding to an Address
Use --bind to choose the host and port. Binding to 0.0.0.0 lets the app accept traffic from outside the container.
gunicorn --bind 0.0.0.0:8000 wsgi:appApp Factory Friendly
Using create_app? Gunicorn can call your factory directly with a function call in the target string.
gunicorn "wsgi:create_app()"Timeouts Keep You Safe
The --timeout flag kills a worker stuck on a slow request. It stops one bad request from freezing the whole server.
gunicorn --timeout 30 wsgi:appNo More Reloader
Gunicorn does not auto-reload on code changes in production. You restart it on deploy, which gives you a predictable release moment.
Logs You Can Trust
Gunicorn writes structured access logs showing each request and its status. Pipe them to stdout so your platform can collect them.
Quick Check
How do you tell Gunicorn which app to run?
Recap
Gunicorn runs your Flask app with real workers, a bind address, and timeouts. Next you will lock all of this into a Docker image. 📦
Frequently asked questions
Is the “Run Flask Under Gunicorn” lesson free?
Yes — the full text of “Run Flask Under Gunicorn” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.
What will I learn in “Run Flask Under Gunicorn”?
Serve the app with multiple workers. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Flask Academy?
No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Run Flask Under Gunicorn” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Flask Academy lesson?
Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Why Not the Built-in Dev Server
- Run Flask Under Gunicorn
- Write a Production Dockerfile
- Front It with Nginx and Compose