From a6afb683ec71be18187bd2d092d0a17db7a170df Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 23:54:17 +0000 Subject: [PATCH 01/13] rely on debug from python --- src/lightning_app/utilities/app_helpers.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/lightning_app/utilities/app_helpers.py b/src/lightning_app/utilities/app_helpers.py index f07ae6bc88c1c..e0e16c67fd18e 100644 --- a/src/lightning_app/utilities/app_helpers.py +++ b/src/lightning_app/utilities/app_helpers.py @@ -511,14 +511,9 @@ def is_static_method(klass_or_instance, attr) -> bool: return isinstance(inspect.getattr_static(klass_or_instance, attr), staticmethod) -def _debugger_is_active() -> bool: - """Return if the debugger is currently active.""" - return hasattr(sys, "gettrace") and sys.gettrace() is not None - - def _should_dispatch_app() -> bool: return ( - _debugger_is_active() + __debug__ and not bool(int(os.getenv("LIGHTNING_DISPATCHED", "0"))) and "LIGHTNING_APP_STATE_URL" not in os.environ ) From 4cf48aaf7811fb5a2eea704f845172a2f5929f8a Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 23:56:00 +0000 Subject: [PATCH 02/13] update --- src/lightning_app/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index 738e82ce9cf12..aa10fbe7386a5 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -56,9 +56,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed the `enable_spawn` method of the `WorkRunExecutor` ([#15812](https://github.com/Lightning-AI/lightning/pull/15812) + - Fixed Sigterm Handler causing thread lock which caused KeyboardInterrupt to hang ([#15881](https://github.com/Lightning-AI/lightning/pull/15881)) +- Fixed detection of a Lightning App running in debug mode ([#15951](https://github.com/Lightning-AI/lightning/pull/15951)) + + ## [1.8.3] - 2022-11-22 ### Changed From 4cb4f6c8344d336a853b23001d9701513c57c68f Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 7 Dec 2022 23:59:26 +0000 Subject: [PATCH 03/13] update --- src/lightning_app/structures/list.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lightning_app/structures/list.py b/src/lightning_app/structures/list.py index f2ff9b4ff2ddf..416f1e6d85a05 100644 --- a/src/lightning_app/structures/list.py +++ b/src/lightning_app/structures/list.py @@ -1,7 +1,5 @@ import typing as t -from pyparsing import Optional - from lightning_app.utilities.app_helpers import _LightningAppRef, _set_child_name T = t.TypeVar("T") @@ -52,7 +50,7 @@ def __init__(self, *items: T): self._name: t.Optional[str] = "" self._last_index = 0 - self._backend: Optional[Backend] = None + self._backend: t.Optional[Backend] = None for item in items: self.append(item) _set_child_name(self, item, str(self._last_index)) From 26633e63066b5939cd66eedc608db88a79be7274 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 12:51:25 +0000 Subject: [PATCH 04/13] update --- .../components/serve/python_server.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/lightning_app/components/serve/python_server.py b/src/lightning_app/components/serve/python_server.py index 1868b0b357fd3..00b570242763b 100644 --- a/src/lightning_app/components/serve/python_server.py +++ b/src/lightning_app/components/serve/python_server.py @@ -113,21 +113,6 @@ def predict(self, request): and this can be accessed as `response.json()["prediction"]` in the client if you are using requests library - - Example: - - >>> from lightning_app.components.serve.python_server import PythonServer - >>> from lightning_app import LightningApp - ... - >>> class SimpleServer(PythonServer): - ... - ... def setup(self): - ... self._model = lambda x: x + " " + x - ... - ... def predict(self, request): - ... return {"prediction": self._model(request.image)} - ... - >>> app = LightningApp(SimpleServer()) """ super().__init__(parallel=True, host=host, port=port, **kwargs) if not issubclass(input_type, BaseModel): From 745b0f62c486bb8125a22eb95f55291fe8502636 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 12:59:59 +0000 Subject: [PATCH 05/13] update --- src/lightning_app/core/app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lightning_app/core/app.py b/src/lightning_app/core/app.py index bcf3c2789098e..82c6dd2d166cd 100644 --- a/src/lightning_app/core/app.py +++ b/src/lightning_app/core/app.py @@ -93,12 +93,10 @@ def __init__( >>> from lightning_app.runners import MultiProcessRuntime >>> class RootFlow(LightningFlow): ... def run(self): - ... print("Hello World!") ... self._exit() ... >>> app = LightningApp(RootFlow()) # application can be dispatched using the `runners`. >>> MultiProcessRuntime(app).dispatch() - Hello World! """ self.root_path = root_path # when running behind a proxy From 9388e4ab7903518e7257e64ed43e2d7d4f170742 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 13:16:45 +0000 Subject: [PATCH 06/13] update --- examples/app_dag/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/app_dag/requirements.txt b/examples/app_dag/requirements.txt index 101182e0cd9ab..f669f518e7389 100644 --- a/examples/app_dag/requirements.txt +++ b/examples/app_dag/requirements.txt @@ -1,2 +1,2 @@ -sklearn +scikit-learn pandas From 362ed46e7657157c3807ca7e041fd9c71baa0392 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 14:05:26 +0000 Subject: [PATCH 07/13] update --- .../components/serve/python_server.py | 15 +++++++++++++++ src/lightning_app/core/app.py | 12 +++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/lightning_app/components/serve/python_server.py b/src/lightning_app/components/serve/python_server.py index 00b570242763b..1868b0b357fd3 100644 --- a/src/lightning_app/components/serve/python_server.py +++ b/src/lightning_app/components/serve/python_server.py @@ -113,6 +113,21 @@ def predict(self, request): and this can be accessed as `response.json()["prediction"]` in the client if you are using requests library + + Example: + + >>> from lightning_app.components.serve.python_server import PythonServer + >>> from lightning_app import LightningApp + ... + >>> class SimpleServer(PythonServer): + ... + ... def setup(self): + ... self._model = lambda x: x + " " + x + ... + ... def predict(self, request): + ... return {"prediction": self._model(request.image)} + ... + >>> app = LightningApp(SimpleServer()) """ super().__init__(parallel=True, host=host, port=port, **kwargs) if not issubclass(input_type, BaseModel): diff --git a/src/lightning_app/core/app.py b/src/lightning_app/core/app.py index d9389ecd27e24..bcf3c2789098e 100644 --- a/src/lightning_app/core/app.py +++ b/src/lightning_app/core/app.py @@ -93,10 +93,12 @@ def __init__( >>> from lightning_app.runners import MultiProcessRuntime >>> class RootFlow(LightningFlow): ... def run(self): + ... print("Hello World!") ... self._exit() ... >>> app = LightningApp(RootFlow()) # application can be dispatched using the `runners`. >>> MultiProcessRuntime(app).dispatch() + Hello World! """ self.root_path = root_path # when running behind a proxy @@ -484,15 +486,7 @@ def _run(self) -> bool: """ self._original_state = deepcopy(self.state) done = False - - # TODO: Re-enable the `ready` property once issues are resolved - if not self.root.ready: - warnings.warn( - "One of your Flows returned `.ready` as `False`. " - "This feature is not yet enabled so this will be ignored.", - UserWarning, - ) - self.ready = True + self.ready = self.root.ready self._start_with_flow_works() From 5aa035d7a83a627e6fcd40b95154732e89877e98 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 14:06:11 +0000 Subject: [PATCH 08/13] update --- src/lightning_app/core/app.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lightning_app/core/app.py b/src/lightning_app/core/app.py index bcf3c2789098e..2279956f7e118 100644 --- a/src/lightning_app/core/app.py +++ b/src/lightning_app/core/app.py @@ -486,7 +486,15 @@ def _run(self) -> bool: """ self._original_state = deepcopy(self.state) done = False - self.ready = self.root.ready + + # TODO: Re-enable the `ready` property once issues are resolved + if not self.root.ready: + warnings.warn( + "One of your Flows returned `.ready` as `False`. " + "This feature is not yet enabled so this will be ignored.", + UserWarning, + ) + self.ready = True self._start_with_flow_works() From 0f55ffc2b75bd3ec4b856a26d4db6b1c23e5b2f7 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 14:11:07 +0000 Subject: [PATCH 09/13] update --- .storage/boring_file.txt | 5 +++++ src/lightning_app/utilities/app_helpers.py | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .storage/boring_file.txt diff --git a/.storage/boring_file.txt b/.storage/boring_file.txt new file mode 100644 index 0000000000000..2a8574fb54178 --- /dev/null +++ b/.storage/boring_file.txt @@ -0,0 +1,5 @@ + +Hello there! +This tab is currently an IFrame of the FastAPI Server running in `DestinationFileAndServeWork`. +Also, the content of this file was created in `SourceFileWork` and then transferred to `DestinationFileAndServeWork`. +Are you already 🤯 ? Stick with us, this is only the beginning. Lightning is 🚀. diff --git a/src/lightning_app/utilities/app_helpers.py b/src/lightning_app/utilities/app_helpers.py index e0e16c67fd18e..ce4dda80ef970 100644 --- a/src/lightning_app/utilities/app_helpers.py +++ b/src/lightning_app/utilities/app_helpers.py @@ -513,9 +513,7 @@ def is_static_method(klass_or_instance, attr) -> bool: def _should_dispatch_app() -> bool: return ( - __debug__ - and not bool(int(os.getenv("LIGHTNING_DISPATCHED", "0"))) - and "LIGHTNING_APP_STATE_URL" not in os.environ + False and not bool(int(os.getenv("LIGHTNING_DISPATCHED", "0"))) and "LIGHTNING_APP_STATE_URL" not in os.environ ) From c27f4e0f293349db68c47f73d3c1edb895fa6616 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 14:11:20 +0000 Subject: [PATCH 10/13] update --- .storage/boring_file.txt | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .storage/boring_file.txt diff --git a/.storage/boring_file.txt b/.storage/boring_file.txt deleted file mode 100644 index 2a8574fb54178..0000000000000 --- a/.storage/boring_file.txt +++ /dev/null @@ -1,5 +0,0 @@ - -Hello there! -This tab is currently an IFrame of the FastAPI Server running in `DestinationFileAndServeWork`. -Also, the content of this file was created in `SourceFileWork` and then transferred to `DestinationFileAndServeWork`. -Are you already 🤯 ? Stick with us, this is only the beginning. Lightning is 🚀. From 1fe087e6a9df06de1fc0ad0971b32a6b4484420a Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 14:24:24 +0000 Subject: [PATCH 11/13] update --- src/lightning_app/utilities/app_helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lightning_app/utilities/app_helpers.py b/src/lightning_app/utilities/app_helpers.py index ce4dda80ef970..665c50889676c 100644 --- a/src/lightning_app/utilities/app_helpers.py +++ b/src/lightning_app/utilities/app_helpers.py @@ -513,7 +513,10 @@ def is_static_method(klass_or_instance, attr) -> bool: def _should_dispatch_app() -> bool: return ( - False and not bool(int(os.getenv("LIGHTNING_DISPATCHED", "0"))) and "LIGHTNING_APP_STATE_URL" not in os.environ + __debug__ + and "_pytest.doctest" not in sys.modules + and not bool(int(os.getenv("LIGHTNING_DISPATCHED", "0"))) + and "LIGHTNING_APP_STATE_URL" not in os.environ ) From e5a2a27010b168426e45bd8afdd603ee8d376c4d Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 14:37:10 +0000 Subject: [PATCH 12/13] update --- src/lightning_app/core/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lightning_app/core/app.py b/src/lightning_app/core/app.py index 2279956f7e118..9663782137c38 100644 --- a/src/lightning_app/core/app.py +++ b/src/lightning_app/core/app.py @@ -98,7 +98,6 @@ def __init__( ... >>> app = LightningApp(RootFlow()) # application can be dispatched using the `runners`. >>> MultiProcessRuntime(app).dispatch() - Hello World! """ self.root_path = root_path # when running behind a proxy From 235956b077057cd27e9ca8c2bd2f7f06ce6f0796 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 8 Dec 2022 14:45:44 +0000 Subject: [PATCH 13/13] update --- src/lightning_app/core/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lightning_app/core/app.py b/src/lightning_app/core/app.py index 9663782137c38..d9389ecd27e24 100644 --- a/src/lightning_app/core/app.py +++ b/src/lightning_app/core/app.py @@ -93,7 +93,6 @@ def __init__( >>> from lightning_app.runners import MultiProcessRuntime >>> class RootFlow(LightningFlow): ... def run(self): - ... print("Hello World!") ... self._exit() ... >>> app = LightningApp(RootFlow()) # application can be dispatched using the `runners`.