forked from orbit-oss/flask
re-add flag to skip unguarded app.run from CLI
This commit is contained in:
parent
ab36542260
commit
5544d09477
3 changed files with 9 additions and 7 deletions
|
|
@ -916,8 +916,8 @@ class Flask(Scaffold):
|
|||
if os.environ.get("FLASK_RUN_FROM_CLI") == "true":
|
||||
if not is_running_from_reloader():
|
||||
click.secho(
|
||||
" * Ignoring a call to 'app.run()', the server is"
|
||||
" already being run with the 'flask run' command.\n"
|
||||
" * Ignoring a call to 'app.run()' that would block"
|
||||
" the current 'flask' CLI command.\n"
|
||||
" Only call 'app.run()' in an 'if __name__ =="
|
||||
' "__main__"\' guard.',
|
||||
fg="red",
|
||||
|
|
|
|||
|
|
@ -715,6 +715,11 @@ class FlaskGroup(AppGroup):
|
|||
parent: click.Context | None = None,
|
||||
**extra: t.Any,
|
||||
) -> click.Context:
|
||||
# Set a flag to tell app.run to become a no-op. If app.run was
|
||||
# not in a __name__ == __main__ guard, it would start the server
|
||||
# when importing, blocking whatever command is being called.
|
||||
os.environ["FLASK_RUN_FROM_CLI"] = "true"
|
||||
|
||||
# Attempt to load .env and .flask env files. The --env-file
|
||||
# option can cause another file to be loaded.
|
||||
if get_load_dotenv(self.load_dotenv):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue