From 2f0c0396b843b2f4a0eb2aed242bd04c6df8cfbd Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Fri, 11 Nov 2022 10:15:12 +0000 Subject: [PATCH] [App] Resolve race condition to move ui files (#15398) --- src/lightning_app/CHANGELOG.md | 3 +++ src/lightning_app/core/app.py | 4 +++- src/lightning_app/runners/cloud.py | 1 + src/lightning_app/runners/multiprocess.py | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index 1be921c5c2..fe494258c1 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -68,6 +68,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed an issue with the `lightning` CLI taking a long time to error out when the cloud is not reachable ([#15412](https://github.com/Lightning-AI/lightning/pull/15412)) +- Fixed race condition to over-write the frontend with app infos ([#15398](https://github.com/Lightning-AI/lightning/pull/15398)) + + ## [1.8.0] - 2022-11-01 diff --git a/src/lightning_app/core/app.py b/src/lightning_app/core/app.py index ef848cce54..17e91d565d 100644 --- a/src/lightning_app/core/app.py +++ b/src/lightning_app/core/app.py @@ -100,6 +100,7 @@ class LightningApp: """ self.root_path = root_path # when running behind a proxy + self.info = info from lightning_app.core.flow import _RootFlow @@ -168,9 +169,10 @@ class LightningApp: logger.debug(f"ENV: {os.environ}") + def _update_index_file(self): # update index.html, # this should happen once for all apps before the ui server starts running. - frontend.update_index_file(FRONTEND_DIR, info=info, root_path=root_path) + frontend.update_index_file(FRONTEND_DIR, info=self.info, root_path=self.root_path) if _should_dispatch_app(): os.environ["LIGHTNING_DISPATCHED"] = "1" diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 81e9e10ebb..c551c1c76e 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -99,6 +99,7 @@ class CloudRuntime(Runtime): app_config = AppConfig.load_from_file(config_file) if config_file else AppConfig() root = config_file.parent if config_file else Path(self.entrypoint_file).absolute().parent cleanup_handle = _prepare_lightning_wheels_and_requirements(root) + self.app._update_index_file() repo = LocalSourceCodeDir(path=root) self._check_uploaded_folder(root, repo) requirements_file = root / "requirements.txt" diff --git a/src/lightning_app/runners/multiprocess.py b/src/lightning_app/runners/multiprocess.py index 1bc8c7b5cf..8abd0a443a 100644 --- a/src/lightning_app/runners/multiprocess.py +++ b/src/lightning_app/runners/multiprocess.py @@ -30,9 +30,11 @@ class MultiProcessRuntime(Runtime): """Method to dispatch and run the LightningApp.""" try: _set_flow_context() + self.app.backend = self.backend self.backend._prepare_queues(self.app) self.backend.resolve_url(self.app, "http://127.0.0.1") + self.app._update_index_file() # set env variables os.environ.update(self.env_vars)