From 8f5168cb31a34c54c9a751cb386b8615e03fb148 Mon Sep 17 00:00:00 2001 From: Bruno Rocha Date: Wed, 18 Apr 2018 12:26:30 -0300 Subject: [PATCH 1/2] Add explicit `(lazy loading)` message to `flask run` related to #2706 --- flask/cli.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/flask/cli.py b/flask/cli.py index 3e2823c7..f137cc1c 100644 --- a/flask/cli.py +++ b/flask/cli.py @@ -614,7 +614,7 @@ def load_dotenv(path=None): return new_dir is not None # at least one file was located and loaded -def show_server_banner(env, debug, app_import_path): +def show_server_banner(env, debug, app_import_path, eager_loading=True): """Show extra startup messages the first time the server is run, ignoring the reloader. """ @@ -622,7 +622,10 @@ def show_server_banner(env, debug, app_import_path): return if app_import_path is not None: - print(' * Serving Flask app "{0}"'.format(app_import_path)) + message = ' * Serving Flask app "{0}"'.format(app_import_path) + if not eager_loading: + message += ' (lazy loading)' + print(message) print(' * Environment: {0}'.format(env)) @@ -759,7 +762,7 @@ def run_command(info, host, port, reload, debugger, eager_loading, if eager_loading is None: eager_loading = not reload - show_server_banner(get_env(), debug, info.app_import_path) + show_server_banner(get_env(), debug, info.app_import_path, eager_loading) app = DispatchingApp(info.load_app, use_eager_loading=eager_loading) from werkzeug.serving import run_simple From 80a9e0edf6208b3c1c9bc28bfb1a5f04b1f59e1d Mon Sep 17 00:00:00 2001 From: David Lord Date: Wed, 18 Apr 2018 13:39:55 -0700 Subject: [PATCH 2/2] app.run is not lazy use click.echo for banner messages --- flask/app.py | 2 +- flask/cli.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/flask/app.py b/flask/app.py index 54ed0402..c482484b 100644 --- a/flask/app.py +++ b/flask/app.py @@ -933,7 +933,7 @@ class Flask(_PackageBoundObject): options.setdefault('use_debugger', self.debug) options.setdefault('threaded', True) - cli.show_server_banner(self.env, self.debug, self.name) + cli.show_server_banner(self.env, self.debug, self.name, False) from werkzeug.serving import run_simple diff --git a/flask/cli.py b/flask/cli.py index f137cc1c..8f054180 100644 --- a/flask/cli.py +++ b/flask/cli.py @@ -614,7 +614,7 @@ def load_dotenv(path=None): return new_dir is not None # at least one file was located and loaded -def show_server_banner(env, debug, app_import_path, eager_loading=True): +def show_server_banner(env, debug, app_import_path, eager_loading): """Show extra startup messages the first time the server is run, ignoring the reloader. """ @@ -623,11 +623,13 @@ def show_server_banner(env, debug, app_import_path, eager_loading=True): if app_import_path is not None: message = ' * Serving Flask app "{0}"'.format(app_import_path) + if not eager_loading: message += ' (lazy loading)' - print(message) - print(' * Environment: {0}'.format(env)) + click.echo(message) + + click.echo(' * Environment: {0}'.format(env)) if env == 'production': click.secho( @@ -636,7 +638,7 @@ def show_server_banner(env, debug, app_import_path, eager_loading=True): click.secho(' Use a production WSGI server instead.', dim=True) if debug is not None: - print(' * Debug mode: {0}'.format('on' if debug else 'off')) + click.echo(' * Debug mode: {0}'.format('on' if debug else 'off')) class CertParamType(click.ParamType):