Eseguire Flask con Gunicorn
Serva l'app con più worker.
Eseguire Flask con Gunicorn è una lezione Flask Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Flask Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Flask Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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. 📦
Domande Frequenti
La lezione «Eseguire Flask con Gunicorn» è gratuita?
Sì — il testo completo di «Eseguire Flask con Gunicorn» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Flask Academy, passa a CoddyKit PRO. Il corso Flask Academy include 4 lezioni in totale.
Cosa imparerò in «Eseguire Flask con Gunicorn»?
Serva l'app con più worker. Eserciti Flask Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Flask Academy?
Non è richiesta alcuna esperienza precedente. Flask Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Eseguire Flask con Gunicorn»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Flask Academy?
Sì. Ogni lezione Flask Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Perché non usare il dev server integrato
- Eseguire Flask con Gunicorn
- Scrivere un Dockerfile per la produzione
- Metterlo davanti a Nginx e Compose