Skip to content
Snippets Groups Projects
Commit 54200e33 authored by Ellis Percival's avatar Ellis Percival
Browse files

Add cleanup function to modules, called upon exit. #16

parent 84233b9d
No related branches found
No related tags found
No related merge requests found
...@@ -44,3 +44,9 @@ class GenericGPIO(object): ...@@ -44,3 +44,9 @@ class GenericGPIO(object):
@abc.abstractmethod @abc.abstractmethod
def get_pin(self, pin): def get_pin(self, pin):
pass pass
def cleanup(self):
"""
Called when closing the program to handle any cleanup operations.
"""
pass
...@@ -43,3 +43,6 @@ class GPIO(GenericGPIO): ...@@ -43,3 +43,6 @@ class GPIO(GenericGPIO):
def get_pin(self, pin): def get_pin(self, pin):
return self.io.input(pin) return self.io.input(pin)
def cleanup(self):
self.io.cleanup()
...@@ -488,3 +488,9 @@ if __name__ == "__main__": ...@@ -488,3 +488,9 @@ if __name__ == "__main__":
finally: finally:
client.disconnect() client.disconnect()
client.loop_stop() client.loop_stop()
for name, gpio in GPIO_MODULES.items():
try:
gpio.cleanup()
except Exception:
_LOG.exception(
"Unable to execute cleanup routine for module %r:", name)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment