mirror of https://github.com/pallets/flask.git
lazy loading preserves click context
This commit is contained in:
parent
3897a51801
commit
aa13521d42
|
@ -42,6 +42,9 @@ Unreleased
|
||||||
- Add an ``--exclude-patterns`` option to the ``flask run`` CLI
|
- Add an ``--exclude-patterns`` option to the ``flask run`` CLI
|
||||||
command to specify patterns that will be ignored by the reloader.
|
command to specify patterns that will be ignored by the reloader.
|
||||||
:issue:`4188`
|
:issue:`4188`
|
||||||
|
- When using lazy loading (the default with the debugger), the Click
|
||||||
|
context from the ``flask run`` command remains available in the
|
||||||
|
loader thread. :issue:`4460`
|
||||||
|
|
||||||
|
|
||||||
Version 2.0.3
|
Version 2.0.3
|
||||||
|
|
|
@ -301,9 +301,17 @@ class DispatchingApp:
|
||||||
self._load_in_background()
|
self._load_in_background()
|
||||||
|
|
||||||
def _load_in_background(self):
|
def _load_in_background(self):
|
||||||
|
# Store the Click context and push it in the loader thread so
|
||||||
|
# script_info is still available.
|
||||||
|
ctx = click.get_current_context(silent=True)
|
||||||
|
|
||||||
def _load_app():
|
def _load_app():
|
||||||
__traceback_hide__ = True # noqa: F841
|
__traceback_hide__ = True # noqa: F841
|
||||||
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
|
if ctx is not None:
|
||||||
|
click.globals.push_context(ctx)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._load_unlocked()
|
self._load_unlocked()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue