diff --git a/src/lava/magma/core/process/process.py b/src/lava/magma/core/process/process.py index 6239072f3..3d9e11a96 100644 --- a/src/lava/magma/core/process/process.py +++ b/src/lava/magma/core/process/process.py @@ -249,6 +249,12 @@ def __init__(self, **kwargs): # Current runtime environment self._runtime: ty.Optional[Runtime] = None + def __del__(self): + """On destruction, terminate Runtime automatically to + free compute resources. + """ + 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 d259e1633..b963eb1df 100644 --- a/src/lava/magma/runtime/runtime.py +++ b/src/lava/magma/runtime/runtime.py @@ -64,6 +64,13 @@ def __init__(self, self.service_to_runtime_data: ty.Iterable[CspRecvPort] = [] self.runtime_to_service_data: ty.Iterable[CspSendPort] = [] + def __del__(self): + """On destruction, terminate Runtime automatically to + free compute resources. + """ + if self._is_started: + self.stop() + def initialize(self): """Initializes the runtime""" # Right now assume there is only 1 node config