تشغيل Flask باستخدام Gunicorn
قدّم التطبيق باستخدام عدة عمال.
تشغيل Flask باستخدام Gunicorn درس مجاني في Flask Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Flask Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Flask Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
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. 📦
تعلم Python مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 30
- الدروس
- 120
الأسئلة الشائعة
هل درس «تشغيل Flask باستخدام Gunicorn» مجاني؟
نعم — نص درس «تشغيل Flask باستخدام Gunicorn» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Flask Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Flask Academy 4 دروس في المجموع.
ماذا ستتعلم في «تشغيل Flask باستخدام Gunicorn»؟
قدّم التطبيق باستخدام عدة عمال. تتمرن على Flask Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Flask Academy؟
لا تُشترط خبرة سابقة. Flask Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «تشغيل Flask باستخدام Gunicorn»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Flask Academy هذا؟
نعم. كل درس في Flask Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- لماذا لا تستخدم خادم التطوير المضمّن
- تشغيل Flask باستخدام Gunicorn
- كتابة Dockerfile للإنتاج
- وضع Nginx في الواجهة واستخدام Compose