Ejecute Flask con Gunicorn
Sirva la aplicación con varios workers.
Ejecute Flask con Gunicorn es una lección gratuita de Flask Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Flask Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Flask Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. 📦
Preguntas frecuentes
¿La lección «Ejecute Flask con Gunicorn» es gratis?
Sí — el texto completo de «Ejecute Flask con Gunicorn» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Flask Academy, actualiza a CoddyKit PRO. El curso de Flask Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Ejecute Flask con Gunicorn»?
Sirva la aplicación con varios workers. Practicas Flask Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Flask Academy?
No se requiere experiencia previa. Flask Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.
¿Cuánto tiempo toma la lección «Ejecute Flask con Gunicorn»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Flask Academy?
Sí. Cada lección de Flask Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Por qué no usar el servidor de desarrollo integrado
- Ejecute Flask con Gunicorn
- Escriba un Dockerfile para producción
- Colóquelo delante de Nginx y Compose