From 57305d62f62defc70c3ef585e692391352d9c81b Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Wed, 10 Nov 2021 15:58:35 -0800 Subject: [PATCH 1/4] Add auto Runtime.stop() Signed-off-by: Marcus G K Williams --- src/lava/magma/core/process/process.py | 6 ++++++ src/lava/magma/runtime/runtime.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/lava/magma/core/process/process.py b/src/lava/magma/core/process/process.py index 27f242221..8b1ac4462 100644 --- a/src/lava/magma/core/process/process.py +++ b/src/lava/magma/core/process/process.py @@ -248,6 +248,12 @@ def __init__(self, **kwargs): # Current runtime environment self._runtime: ty.Optional[Runtime] = None + def __del__(self): + """On destructor call automatically + stop the process. + """ + self.stop() + def _post_init(self): """Called after __init__() method of any sub class via ProcessMetaClass to finalize initialization leading to following diff --git a/src/lava/magma/runtime/runtime.py b/src/lava/magma/runtime/runtime.py index c899e4dc2..528796e9f 100644 --- a/src/lava/magma/runtime/runtime.py +++ b/src/lava/magma/runtime/runtime.py @@ -57,6 +57,13 @@ def __init__(self, run_cond: AbstractRunCondition, exe: Executable): self.service_to_runtime_data: ty.Iterable[CspRecvPort] = [] self.runtime_to_service_data: ty.Iterable[CspSendPort] = [] + def __del__(self): + """On destructor call automatically + stop the Runtime. + """ + if self._is_started: + self.stop() + def initialize(self): """Initializes the runtime""" # Right now assume there is only 1 node config From 83e3e7732dbb3d9736cc8ac02c81e4d54b7b1b6b Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Thu, 11 Nov 2021 13:43:51 -0800 Subject: [PATCH 2/4] Update process.py change __del__ docstring --- src/lava/magma/core/process/process.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lava/magma/core/process/process.py b/src/lava/magma/core/process/process.py index ab2b46392..3d9e11a96 100644 --- a/src/lava/magma/core/process/process.py +++ b/src/lava/magma/core/process/process.py @@ -250,8 +250,8 @@ def __init__(self, **kwargs): self._runtime: ty.Optional[Runtime] = None def __del__(self): - """On destructor call automatically - stop the process. + """On destruction, terminate Runtime automatically to + free compute resources. """ self.stop() From 99c4eda6ef71ea0de6b7cf0d39c19b18816bb9ed Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Thu, 11 Nov 2021 13:45:03 -0800 Subject: [PATCH 3/4] Update runtime.py change docstring --- src/lava/magma/runtime/runtime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lava/magma/runtime/runtime.py b/src/lava/magma/runtime/runtime.py index 70948aff6..50e89b630 100644 --- a/src/lava/magma/runtime/runtime.py +++ b/src/lava/magma/runtime/runtime.py @@ -65,8 +65,8 @@ def __init__(self, self.runtime_to_service_data: ty.Iterable[CspSendPort] = [] def __del__(self): - """On destructor call automatically - stop the Runtime. + """On destruction, terminate Runtime automatically to + free compute resources. """ if self._is_started: self.stop() From a6e07774ff11e8bcfd7b00798772911e60399efc Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Thu, 11 Nov 2021 13:47:48 -0800 Subject: [PATCH 4/4] Update runtime.py fix __del__ docstring --- src/lava/magma/runtime/runtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lava/magma/runtime/runtime.py b/src/lava/magma/runtime/runtime.py index 50e89b630..b963eb1df 100644 --- a/src/lava/magma/runtime/runtime.py +++ b/src/lava/magma/runtime/runtime.py @@ -65,7 +65,7 @@ def __init__(self, self.runtime_to_service_data: ty.Iterable[CspSendPort] = [] def __del__(self): - """On destruction, terminate Runtime automatically to + """On destruction, terminate Runtime automatically to free compute resources. """ if self._is_started: