Merge pull request #97 from s-allius/s-allius/issue93

S allius/issue93
This commit is contained in:
Stefan Allius
2024-06-16 13:09:16 +02:00
committed by GitHub
6 changed files with 13 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [unreleased]
- MODBUS close handler releases internal resource [#93](https://github.com/s-allius/tsun-gen3-proxy/issues/93)
- add exception handling for message forwarding [#94](https://github.com/s-allius/tsun-gen3-proxy/issues/94)
- print imgae build time during proxy start
- add type annotations

View File

@@ -61,7 +61,6 @@ class AsyncStream():
"""Async loop handler for precessing all received messages"""
self.r_addr = self.writer.get_extra_info('peername')
self.l_addr = self.writer.get_extra_info('sockname')
while True:
try:
await self.__async_read()

View File

@@ -122,7 +122,7 @@ class InverterG3(Inverter, ConnectionG3):
def close(self) -> None:
logging.debug(f'InverterG3.close() l{self.l_addr} | r{self.r_addr}')
super().close() # call close handler in the parent class
# logger.debug (f'Inverter refs: {gc.get_referrers(self)}')
# logging.info(f'Inverter refs: {gc.get_referrers(self)}')
def __del__(self):
logging.debug("InverterG3.__del__")

View File

@@ -97,7 +97,7 @@ class Message(metaclass=IterRegistry):
'''
def close(self) -> None:
if self.mb:
del self.mb
self.mb.close()
self.mb = None
pass # pragma: no cover

View File

@@ -105,7 +105,16 @@ class Modbus():
self.req_pend = False
self.tim = None
def close(self):
"""free the queue and erase the callback handlers"""
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,

View File

@@ -106,7 +106,7 @@ if __name__ == "__main__":
handle_shutdown(loop)))
#
# Create taska for our listening servera. These must be tasks! If we call
# Create tasks for our listening servers. These must be tasks! If we call
# start_server directly out of our main task, the eventloop will be blocked
# and we can't receive and handle the UNIX signals!
#