diff --git a/huber/driver.py b/huber/driver.py index 9e1725f..7c461cb 100644 --- a/huber/driver.py +++ b/huber/driver.py @@ -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() @@ -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: @@ -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): diff --git a/setup.py b/setup.py index 6703b14..44c3afa 100644 --- a/setup.py +++ b/setup.py @@ -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',