Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightning apps: add flow fail() #18883

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lightning/app/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from lightning.app.utilities.commands.base import _process_requests
from lightning.app.utilities.component import _convert_paths_after_init, _validate_root_flow
from lightning.app.utilities.enum import AppStage, CacheCallsKeys
from lightning.app.utilities.exceptions import CacheMissException, ExitAppException
from lightning.app.utilities.exceptions import CacheMissException, ExitAppException, LightningFlowException
from lightning.app.utilities.layout import _collect_layout
from lightning.app.utilities.proxies import ComponentDelta
from lightning.app.utilities.scheduler import SchedulerThread
Expand Down Expand Up @@ -462,6 +462,9 @@ def run_once(self) -> bool:
self.root.run()
except CacheMissException:
self._on_cache_miss_exception()
except LightningFlowException:
done = True
self.stage = AppStage.FAILED
except (ExitAppException, KeyboardInterrupt):
done = True
self.stage = AppStage.STOPPING
Expand Down
8 changes: 7 additions & 1 deletion src/lightning/app/core/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from lightning.app.storage.path import Path
from lightning.app.utilities.app_helpers import _is_json_serializable, _LightningAppRef, _set_child_name, is_overridden
from lightning.app.utilities.component import _sanitize_state
from lightning.app.utilities.exceptions import ExitAppException
from lightning.app.utilities.exceptions import ExitAppException, LightningFlowException
from lightning.app.utilities.introspection import _is_init_context, _is_run_context
from lightning.app.utilities.packaging.cloud_compute import CloudCompute, _maybe_create_cloud_compute

Expand Down Expand Up @@ -391,6 +391,12 @@ def stop(self, end_msg: str = "") -> None:
print(end_msg)
raise ExitAppException

def fail(self, end_msg: str = "") -> None:
"""Method used to exit and fail the application."""
if end_msg:
print(end_msg)
raise LightningFlowException

def _exit(self, end_msg: str = "") -> None:
"""Used to exit the application.

Expand Down