question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning: Silently ignoring app.run() because the application is run from the flask command line executable

See original GitHub issue

An 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:open
  • Created a year ago
  • Reactions:1
  • Comments:26 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
reubanocommented, Jun 16, 2022

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

os.environ.pop("FLASK_RUN_FROM_CLI")
app.run(debug=False, use_reloader=False)
1reaction
rycus86commented, Jun 2, 2022

They already have different (more robust?) ways to expose metrics over HTTP, see https://github.com/prometheus/client_python#http

so it is not secure and should not be used in production

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found