diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index 5673fcadf48d0..3b221b982728a 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -32,6 +32,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed debugging with VSCode IDE ([#15747](https://github.com/Lightning-AI/lightning/pull/15747)) +- Fixed the work not stopped when successful when passed directly to the LightningApp ([#15801](https://github.com/Lightning-AI/lightning/pull/15801)) + + ## [1.8.2] - 2022-11-17 ### Added diff --git a/src/lightning_app/core/flow.py b/src/lightning_app/core/flow.py index 18b6fd40f756a..3773c7a0dd4f0 100644 --- a/src/lightning_app/core/flow.py +++ b/src/lightning_app/core/flow.py @@ -758,6 +758,9 @@ def __init__(self, work): self.work = work def run(self): + if self.work.has_succeeded: + self.work.stop() + self._exit() self.work.run() def configure_layout(self): diff --git a/tests/tests_app/core/test_lightning_app.py b/tests/tests_app/core/test_lightning_app.py index 64bee758af5d5..8bc6c6418e81c 100644 --- a/tests/tests_app/core/test_lightning_app.py +++ b/tests/tests_app/core/test_lightning_app.py @@ -1134,3 +1134,14 @@ def test_lightning_flow_properties(): assert flow._value is None flow.run() assert flow._value is True + + +class SimpleWork2(LightningWork): + def run(self): + pass + + +def test_lightning_work_stopped(): + + app = LightningApp(SimpleWork2()) + MultiProcessRuntime(app, start_server=False).dispatch()