add a close handler to release internal resources

This commit is contained in:
Stefan Allius
2024-06-16 11:56:03 +02:00
parent b053c7e576
commit f9b02f3486

View File

@@ -105,7 +105,16 @@ class Modbus():
self.req_pend = False
self.tim = None
def close(self):
"""free the queue and the callback handler"""
logging.debug('Modbus close:')
self.rsp_handler = None
self.snd_handler = None
while not self.que.empty:
self.que.get_nowait()
def __del__(self):
"""log statistics on the deleting of a MODBUS instance"""
logging.debug(f'Modbus __del__:\n {self.counter}')
def build_msg(self, addr: int, func: int, reg: int, val: int,