From f9b02f34861e3b3fb6afe9b961f09200aab2c35b Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Sun, 16 Jun 2024 11:56:03 +0200 Subject: [PATCH] add a close handler to release internal resources --- app/src/modbus.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/modbus.py b/app/src/modbus.py index 8f3778b..fdb7c24 100644 --- a/app/src/modbus.py +++ b/app/src/modbus.py @@ -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,