-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot call app.run() from custom cli command #2776
Comments
FYI, I included a fix for this problem in #2781. |
I've found a solution to this that works in my case. I needed to have a separate flask app as a click command which failed when upgrading to 1.0. In my situation, I created I think I prefer the fix in your PR but wanted to throw this out there as an option that may work for some people's use case. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
I think the most I want to do here is to move the |
Actually, I don't think it would be good to only set that from Disabling this check is a pretty uncommon requirement, it would only come up if you're writing a custom def custom_run():
del os.environ["FLASK_RUN_FROM_CLI"]
app.run() I'm doing some other work on the CLI, I might think of a more "official" way to turn off this check. For now the env var is fine, even though it's not really a public API. Just pay attention to our changelog if unsetting it is something your library depends on. |
Expected Behavior
There are situations in which you may want to implement a custom application runner. Two examples that I can think of are running the application under the Werkzeug profiler, and starting the application in a background thread to perform integration tests against it.
In these situations, most people would want to create a custom CLI command that calls
app.run()
to start the application after applying any necessary changes, such as enabling profiling, etc.Example
bug.py
:What I expect with the above example is that running
flask custom_run
starts the development web server.Actual Behavior
I think this warning should only appear when
app.run()
is called from the global scope of the main module. This can be determined from the number of frames in the call stack. The warning should be issued only if the call stack has two frames, but should not if there are more than two. Thoughts?The text was updated successfully, but these errors were encountered: