diff --git a/dsmr_parser/clients/socket_.py b/dsmr_parser/clients/socket_.py index 968a582..8976aaf 100644 --- a/dsmr_parser/clients/socket_.py +++ b/dsmr_parser/clients/socket_.py @@ -31,11 +31,15 @@ def read(self): buffer = b"" with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as socket_handle: - + socket_handle.settimeout(60) socket_handle.connect((self.host, self.port)) while True: - buffer += socket_handle.recv(self.BUFFER_SIZE) + try: + buffer += socket_handle.recv(self.BUFFER_SIZE) + except socket.timeout: + logger.error("Socket timeout occurred, exiting") + break lines = buffer.splitlines(keepends=True) diff --git a/tox.ini b/tox.ini index 59d57e7..8f20f71 100644 --- a/tox.ini +++ b/tox.ini @@ -14,6 +14,9 @@ commands= [pylama:dsmr_parser/clients/__init__.py] ignore = W0611 +[pylama:dsmr_parser/clients/socket_.py] +ignore = C901 + [pylama:dsmr_parser/parsers.py] ignore = W605 @@ -24,4 +27,4 @@ ignore = E501 max_line_length = 120 [pylama:pycodestyle] -max_line_length = 120 \ No newline at end of file +max_line_length = 120