Skip to content

Commit

Permalink
Add auto Runtime.stop() (lava-nc#38)
Browse files Browse the repository at this point in the history
* Add auto Runtime.stop()

Signed-off-by: Marcus G K Williams <[email protected]>

* Update process.py change __del__ docstring

* Update runtime.py change docstring

* Update runtime.py fix __del__ docstring

Co-authored-by: PhilippPlank <[email protected]>
  • Loading branch information
mgkwill and PhilippPlank committed Nov 16, 2021
1 parent a1ba4b9 commit d223d62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lava/magma/core/process/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/lava/magma/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d223d62

Please sign in to comment.