lava-nc / lava

A Software Framework for Neuromorphic Computing
https://lava-nc.org
Other
529 stars 136 forks source link

Creating a process and never running it causes an error when the process is deleted. #759

Open tim-shea opened 11 months ago

tim-shea commented 11 months ago

Describe the bug When I create an object that derives from AbstractProcess and never call run, it should not invoke stop during garbage collection.

To reproduce current behavior

from lava.magma.core.process.process import AbstractProcess

class ClientProcess(AbstractProcess):
    def __init__(self):
        pass

if __name__ == '__main__':
    client = ClientProcess()
  1. I get this error ...
    Traceback (most recent call last):
    File "/Users/tshea/Documents/ronan/remote_loihi_poc/snippets/echo_client.py", line 37, in <module>
    client = ClientProcess()
             ^^^^^^^^^^^^^^^
    File "/Users/tshea/Documents/ronan/lava/src/lava/magma/core/process/process.py", line 33, in __call__
    getattr(obj, "_post_init")()
    File "/Users/tshea/Documents/ronan/lava/src/lava/magma/core/process/process.py", line 239, in _post_init
    attrs = self._find_attr_by_type(OutPort)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Users/tshea/Documents/ronan/lava/src/lava/magma/core/process/process.py", line 260, in _find_attr_by_type
    attr = getattr(self, attr_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Users/tshea/Documents/ronan/lava/src/lava/magma/core/process/process.py", line 445, in is_compiled
    return self._is_compiled
           ^^^^^^^^^^^^^^^^^
    AttributeError: 'ClientProcess' object has no attribute '_is_compiled'. Did you mean: 'is_compiled'?
    Exception ignored in: <function AbstractProcess.__del__ at 0x107d36d40>
    Traceback (most recent call last):
    File "/Users/tshea/Documents/ronan/lava/src/lava/magma/core/process/process.py", line 221, in __del__
    self.stop()
    File "/Users/tshea/Documents/ronan/lava/src/lava/magma/core/process/process.py", line 414, in stop
    if self.runtime:
       ^^^^^^^^^^^^
    File "/Users/tshea/Documents/ronan/lava/src/lava/magma/core/process/process.py", line 275, in runtime
    return self._runtime
           ^^^^^^^^^^^^^
    AttributeError: 'ClientProcess' object has no attribute '_runtime'

Expected behavior No error should be produced.

Environment (please complete the following information):