What the flask development server warning actually means, why it matters in production, and how to fix it with a proper WSGI server.
"This Is a Development Server" Flask Warning — What It Means and How to Fix It
If you've run a Flask app with app.run() and seen this in your logs:
WARNING: This is a development server. Do not use it in a production deployment.
Enter fullscreen mode Exit fullscreen mode
you've hit one of the most common warnings in the Python web ecosystem. It looks alarming, but it's telling you something specific and fixable. Here's what the flask development server warning actually means, and how to resolve it properly.
Table of Contents
- What the Warning Is Actually Saying
- Why the Dev Server Isn't Production-Ready
- The Standard Fix: A Real WSGI Server
- Fixing It Automatically with StayPresent
- When the Warning Is Harmless
- Verifying Which Server Is Actually Running
- Full Example
- FAQs
- Conclusion
What the Warning Is Actually Saying
Flask's built-in server (app.run()) was designed for local development — quick iteration, auto-reload, helpful tracebacks in the browser. It was never intended to be the thing actually serving real user traffic. The warning is Flask itself telling you exactly that, not a sign that something is broken.
Why the Dev Server Isn't Production-Ready
The development server is single-threaded by default (or thread-per-request in a fairly naive way), lacks the connection handling and worker management a production WSGI server provides, and isn't hardened against the kind of concurrent load or malformed requests real-world traffic can produce. For a genuinely low-traffic keep-alive endpoint, this often doesn't matter much in practice — but for anything serving actual users, or receiving health checks from a busy platform, it's worth fixing properly rather than ignoring the warning.
The Standard Fix: A Real WSGI Server
The conventional fix is to run your Flask app behind a production WSGI server instead of app.run() — common choices include Gunicorn (Unix-only) and Waitress (cross-platform, including Windows). Waitress is a pure-Python WSGI server, which makes it a natural fit for projects that want to avoid extra system-level dependencies:
from waitress import serve
from myapp import app
serve(app, host="0.0.0.0", port=8080)
Enter fullscreen mode Exit fullscreen mode
This alone eliminates the warning, since Flask's own dev server is never invoked at all.
Fixing It Automatically with StayPresent
If your Flask app is specifically the keep-alive server running alongside a bot, StayPresent handles this switch automatically — no manual Waitress wiring required. Installing the prod extra is enough:
pip install staypresent[prod]
Enter fullscreen mode Exit fullscreen mode
import staypresent
staypresent.web.json({"status": "running"})
staypresent.run("bot.py") # uses Waitress automatically if installed
Enter fullscreen mode Exit fullscreen mode
production=True is StayPresent's default, and it uses Waitress whenever it's installed and available — silently falling back to Flask's own dev server (with the same one-time warning) only if Waitress isn't present. Install the prod extra once, and the warning disappears without any additional code.
When the Warning Is Harmless
For a purely local script you're running on your own machine and never exposing to real traffic, the dev server is genuinely fine — that's exactly what it's for. The warning matters specifically once your service is reachable by anything other than you: a hosting platform's health checker, real users, or another service calling into it.
Verifying Which Server Is Actually Running
With StayPresent, a quick way to confirm Waitress is actually being used (rather than the fallback) is to check the startup log line from the "staypresent" logger, which explicitly states which server backend it bound with:
import logging
logging.getLogger("staypresent").setLevel(logging.INFO)
Enter fullscreen mode Exit fullscreen mode
If Waitress isn't installed, or production=False was passed explicitly, the log will say so — which is the fastest way to confirm whether you still need to install the prod extra.
Full Example
import os
import staypresent
staypresent.web.json({"status": "running"})
staypresent.run(
"bot.py",
port=int(os.getenv("PORT", 8080)),
production=True, # default; uses Waitress if installed
threads=8,
)
Enter fullscreen mode Exit fullscreen mode
pip install staypresent[prod]
Enter fullscreen mode Exit fullscreen mode
FAQs
Does installing Waitress alone fix the warning, or do I need code changes too?
With StayPresent, installing Waitress (via the prod extra) is enough — production=True is already the default, so no code changes are needed once the package is installed.
Is Gunicorn a better choice than Waitress?
Both are legitimate production WSGI servers; Gunicorn is Unix-only (no native Windows support), while Waitress is cross-platform and pure-Python, which is why StayPresent uses it specifically.
Can I force Flask's dev server even after installing Waitress?
Yes — pass production=False to staypresent.run() if you deliberately want the dev server for some reason (e.g. debugging a specific request in isolation).
Conclusion
The flask development server warning isn't a bug report — it's Flask correctly telling you it wasn't built for production traffic. The fix is a real WSGI server like Waitress, and if you're already using StayPresent for a bot's keep-alive endpoint, that fix is a single pip install staypresent[prod] away.
pip install staypresent[prod]
Enter fullscreen mode Exit fullscreen mode
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.