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

Commit

Permalink
Merge pull request #40 from numat/increase_timeout
Browse files Browse the repository at this point in the history
📝 Increase default timeout to 500ms, and make it adjustable
  • Loading branch information
juli4nb4dillo authored Nov 14, 2024
2 parents 451c117 + 1ff763f commit 6bb86db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 6bb86db

Please sign in to comment.