Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

📝 Increase default timeout to 500ms, and make it adjustable #40

Merged
merged 1 commit into from
Nov 14, 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
9 changes: 5 additions & 4 deletions huber/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ class Bath:
'status'
]

def __init__(self, ip):
def __init__(self, ip, max_timeouts=10, comm_timeout=0.5):
"""Initialize the connection with the bath's IP address."""
self.ip = ip
self.open = False
self.reconnecting = False
self.timeouts = 0
self.max_timeouts = 10
self.max_timeouts = max_timeouts
self.comm_timeout = comm_timeout
self.connection = {}
self.lock = asyncio.Lock()

Expand Down Expand Up @@ -199,7 +200,7 @@ async def _handle_connection(self):
"""Automatically maintain TCP connection."""
try:
if not self.open:
await asyncio.wait_for(self._connect(), timeout=0.25)
await asyncio.wait_for(self._connect(), timeout=self.comm_timeout)
self.reconnecting = False
except (asyncio.TimeoutError, OSError):
if not self.reconnecting:
Expand All @@ -211,7 +212,7 @@ async def _handle_communication(self, command):
try:
self.connection['writer'].write(command.encode())
future = self.connection['reader'].readuntil(b'\r\n')
line = await asyncio.wait_for(future, timeout=0.25)
line = await asyncio.wait_for(future, timeout=self.comm_timeout)
result = line.decode().strip()
self.timeouts = 0
except (asyncio.TimeoutError, TypeError, OSError):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='huber',
version='0.6.0',
version='0.6.1',
description='Python driver for Huber recirculating baths.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down