Warning: Silently ignoring app.run() because the application is run from the flask command line executable
See original GitHub issueAn awkward situation. Code:
metrics = prometheus_flask_exporter.PrometheusMetrics(app)
metrics.start_http_server(8081, host=config.METRICS_HOST)
Result:
website_1 | * Serving Flask app 'src.app:app' (lazy loading)
website_1 | * Environment: development
website_1 | * Debug mode: on
website_1 | /usr/local/lib/python3.8/dist-packages/prometheus_flask_exporter/__init__.py:322: Warning: Silently ignoring app.run() because the application is run from the flask command line executable. Consider putting app.run() behind an if __name__ == "__main__" guard to silence this warning.
And the metrics server does not listen on port 8081. It seems that Flask notices that I have invoked the main application using flask run
, and has elected to disable the ability to run new Flask applications, which obviously breaks start_http_server
from prometheus_flask_exporter.
Not sure what the best way to handle this is, but wanted to flag.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:26 (7 by maintainers)
Top Results From Across the Web
How to start Flask and Flask-SocketIO via the command line ...
Try installing them first. After installing one of them, you can just use flask run to start your application. Share.
Read more >How to Run a Flask Application - Twilio
In-depth look at the two methods to run a Flask application server during development.
Read more >Command Line Interface — Flask Documentation (2.2.x)
The flask command is installed by Flask, not your application; it must be told where to find your application in order to use...
Read more >Settings Reference for Python - Visual Studio Code
Note that Visual Studio code ignores this setting when debugging because it ... shown such as startup information and commands run by the...
Read more >Changelog — Python 3.11.1 documentation
gh-90081: Run Python code in tracer/profiler function at full speed. ... and set as the default app for *.py files, command line arguments ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My suggestion was an alternative to
os.environ.pop("FLASK_ENV")
. You should still use a Production server in production. But the Flask dev server is fine in development.In my case, I’m doing the following
They already have different (more robust?) ways to expose metrics over HTTP, see https://github.com/prometheus/client_python#http
Maybe this is worth calling out in this project’s README, and suggest some alternatives - though on that note I think if you run the metrics endpoint on an insecure server that is not available for external users, it may be something that is an acceptable tradeoff for some. I liked @raxod502 's suggestion to package up the metrics exposure code as a function so that people can bring their own (more secure) servers to serve it with, and perhaps here we can explain in the README that it’s more recommended than the other alternative.