lazy loading preserves click context

This commit is contained in:
David Lord 2022-02-22 19:04:03 -08:00
parent 3897a51801
commit aa13521d42
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 11 additions and 0 deletions

View file

@ -301,9 +301,17 @@ class DispatchingApp:
self._load_in_background()
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():
__traceback_hide__ = True # noqa: F841
with self._lock:
if ctx is not None:
click.globals.push_context(ctx)
try:
self._load_unlocked()
except Exception as e: