35
35
_should_dispatch_app ,
36
36
Logger ,
37
37
)
38
+ from lightning_app .utilities .app_status import AppStatus
38
39
from lightning_app .utilities .commands .base import _process_requests
39
40
from lightning_app .utilities .component import _convert_paths_after_init , _validate_root_flow
40
41
from lightning_app .utilities .enum import AppStage , CacheCallsKeys
@@ -140,6 +141,7 @@ def __init__(
140
141
self .exception = None
141
142
self .collect_changes : bool = True
142
143
144
+ self .status : Optional [AppStatus ] = None
143
145
# TODO: Enable ready locally for opening the UI.
144
146
self .ready = False
145
147
@@ -150,6 +152,7 @@ def __init__(
150
152
self .checkpointing : bool = False
151
153
152
154
self ._update_layout ()
155
+ self ._update_status ()
153
156
154
157
self .is_headless : Optional [bool ] = None
155
158
@@ -418,6 +421,7 @@ def run_once(self):
418
421
419
422
self ._update_layout ()
420
423
self ._update_is_headless ()
424
+ self ._update_status ()
421
425
self .maybe_apply_changes ()
422
426
423
427
if self .checkpointing and self ._should_snapshot ():
@@ -485,19 +489,12 @@ def _run(self) -> bool:
485
489
self ._original_state = deepcopy (self .state )
486
490
done = False
487
491
488
- # TODO: Re-enable the `ready` property once issues are resolved
489
- if not self .root .ready :
490
- warnings .warn (
491
- "One of your Flows returned `.ready` as `False`. "
492
- "This feature is not yet enabled so this will be ignored." ,
493
- UserWarning ,
494
- )
495
- self .ready = True
492
+ self .ready = self .root .ready
496
493
497
494
self ._start_with_flow_works ()
498
495
499
- if self .ready and self . should_publish_changes_to_api and self .api_publish_state_queue :
500
- self .api_publish_state_queue .put (self .state_vars )
496
+ if self .should_publish_changes_to_api and self .api_publish_state_queue is not None :
497
+ self .api_publish_state_queue .put (( self .state_vars , self . status ) )
501
498
502
499
self ._reset_run_time_monitor ()
503
500
@@ -506,8 +503,8 @@ def _run(self) -> bool:
506
503
507
504
self ._update_run_time_monitor ()
508
505
509
- if self .ready and self . _has_updated and self .should_publish_changes_to_api and self .api_publish_state_queue :
510
- self .api_publish_state_queue .put (self .state_vars )
506
+ if self ._has_updated and self .should_publish_changes_to_api and self .api_publish_state_queue is not None :
507
+ self .api_publish_state_queue .put (( self .state_vars , self . status ) )
511
508
512
509
self ._has_updated = False
513
510
@@ -532,6 +529,23 @@ def _update_is_headless(self) -> None:
532
529
# This ensures support for apps which dynamically add a UI at runtime.
533
530
_handle_is_headless (self )
534
531
532
+ def _update_status (self ) -> None :
533
+ old_status = self .status
534
+
535
+ work_statuses = {}
536
+ for work in breadth_first (self .root , types = (lightning_app .LightningWork ,)):
537
+ work_statuses [work .name ] = work .status
538
+
539
+ self .status = AppStatus (
540
+ is_ui_ready = self .ready ,
541
+ work_statuses = work_statuses ,
542
+ )
543
+
544
+ # If the work statuses changed, the state delta will trigger an update.
545
+ # If ready has changed, we trigger an update manually.
546
+ if self .status != old_status :
547
+ self ._has_updated = True
548
+
535
549
def _apply_restarting (self ) -> bool :
536
550
self ._reset_original_state ()
537
551
# apply stage after restoring the original state.
0 commit comments