Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add socket timeout #155

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dsmr_parser/clients/socket_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,4 +27,4 @@ ignore = E501
max_line_length = 120

[pylama:pycodestyle]
max_line_length = 120
max_line_length = 120
Loading