From 240a11052bb2ef1ba0bbcc5d503601a175926f75 Mon Sep 17 00:00:00 2001 From: David Lord Date: Mon, 18 Nov 2019 12:36:00 -0800 Subject: [PATCH] lazy load app on reload only --- CHANGES.rst | 3 +++ src/flask/cli.py | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index fb211c08..859aaf35 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,9 @@ Unreleased - Add :meth:`Config.from_file` to load config using arbitrary file loaders, such as ``toml.load`` or ``json.load``. :meth:`Config.from_json` is deprecated in favor of this. :pr:`3398` +- The ``flask run`` command will only defer errors on reload. Errors + present during the initial call will cause the server to exit with + the traceback immediately. :issue:`3431` Version 1.1.2 diff --git a/src/flask/cli.py b/src/flask/cli.py index c09b2cd0..4778df30 100644 --- a/src/flask/cli.py +++ b/src/flask/cli.py @@ -296,11 +296,15 @@ class DispatchingApp(object): of the Werkzeug debugger means that it shows up in the browser. """ - def __init__(self, loader, use_eager_loading=False): + def __init__(self, loader, use_eager_loading=None): self.loader = loader self._app = None self._lock = Lock() self._bg_loading_exc_info = None + + if use_eager_loading is None: + use_eager_loading = os.environ.get("WERKZEUG_RUN_MAIN") != "true" + if use_eager_loading: self._load_unlocked() else: @@ -841,9 +845,6 @@ def run_command( if debugger is None: debugger = debug - if eager_loading is None: - eager_loading = not reload - show_server_banner(get_env(), debug, info.app_import_path, eager_loading) app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)