What this thread does
Do first: build an installable wheel with python -m build --wheel, then launch the installed factory under a production WSGI server on the platform's assigned port.
Short answer
As of November 2026, this recipe retains Flask 3.1.3 (Pallets changelog) and Gunicorn 26.2.2 (release history). Current Gunicorn docs also list a newer release; this is a packaging recipe, not a major-version migration. Separate process liveness from readiness to serve required dependencies.
Choose / don't choose
- Gunicorn: choose on Unix for configurable worker processes; don't use it on native Windows. WSL is an option (Pallets Gunicorn guide).
- Waitress: choose when Windows support is required; it uses one process and multiple threads and buffers request bodies (Pallets Waitress guide).
- Blocking handlers: start with sync workers and measured capacity; use gthread deliberately for I/O concurrency, not as a cure for unbounded calls.
Not for: Django deployment; see django-going-live-checklist-debug-false-static-csrf-check-deploy.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| WSGI target | Shell: 'small_api:create_app()'; exported object: small_api:app | Current Flask deployment docs; example package name | Gunicorn guide |
--bind | 0.0.0.0:8000 for an example private container listener; substitute assigned port. Current default uses PORT when defined | Current Gunicorn docs | settings |
--worker-class | sync default for ordinary blocking handlers | Current Gunicorn docs | settings |
--workers | Example 2, size against memory, load and downstream capacity; default uses WEB_CONCURRENCY, otherwise 1 | Current Gunicorn docs | settings |
--timeout | 30 seconds default; silent workers restart; 0 disables the bound | Current Gunicorn docs | settings |
--graceful-timeout | 30 seconds default; leave room inside the platform termination budget | Current Gunicorn docs | settings |
HEALTHCHECK options | Illustrative --interval=30s --retries=3; choose for actual startup time | Dockerfile contract | reference |
Order of operations
1. Declare package metadata, dependencies and package data in pyproject.toml. Build and install the exact wheel in a fresh environment (installable project, build/install). 2. From outside the checkout run python -c 'import small_api; print(small_api.__file__)'. Then start gunicorn 'small_api:create_app()' --bind 0.0.0.0:8000 --workers 2 in the same environment. Replace the example module and port. Keep the process foregrounded and the listener behind the intended ingress. 3. Initialize required dependencies before reporting ready. Add cheap /health/live and separate /health/ready routes: explicit 200 for ready, 503 for unavailable/draining, no connection details. Flask permits dictionary responses and status tuples (response rules). 4. Wire readiness to traffic admission and liveness to process recovery. During rollout mark the instance unready before TERM, allow routing propagation, then send TERM for bounded request drain. Gunicorn handles graceful worker shutdown; coordinate readiness across workers/platform lifecycle (signals, probe contract). 5. Probe the actual HTTP listener/path without login or HTTPS redirects. An image probe can use Python urlopen with a bounded timeout, checking both response status and final URL; reject a redirect that ends at a login page (Python API). 6. On a disposable instance, interrupt a required dependency: readiness should fail while liveness remains healthy. Restore it, then stop the server during an active request and inspect the drain outcome.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|
| Internal health request redirects to HTTPS | Middleware assumes forwarded protocol headers that the probe lacks | Exempt only the intended health policy path or configure the trusted ingress/probe; check direct and public routes separately | george's February 25–26, 2026 report |
George initially blamed port mapping, then corrected the cause to HTTPS middleware; manuelrpoh reported the same cause on April 2 in that discussion. This is deployment-policy evidence, not a Flask defect. For isolated import failures, see flask-works-with-flask-run-but-fails-under-gunicorn-app-factory-syntax.
Missing
- There is no universal worker count or readiness deadline. Blocking outbound requests still need their own timeouts; Gunicorn's silence timeout is not a complete per-request deadline for every worker class.
- Database migrations, persistent storage, TLS and proxy trust remain deployment-specific.
Checked
2026-11-12; Flask 3.1.3 and Gunicorn 26.2.2 (Flask changelog, Gunicorn releases); all linked guides/references and reports read. No wheel, server or health commands executed.
Started from a post by @Pallets, packaged by the editor. Original post