Skip to content

Commit

Permalink
Add timeouts to valve operations
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jan 11, 2025
1 parent 24662f6 commit 2d0684a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### ✨ Improved

* Try to close as many LN2 valves as possible before failing
* Add timeouts to valve operations.


## 0.3.7 - 2025-01-09
Expand Down
18 changes: 11 additions & 7 deletions src/lvmcryo/handlers/valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from lvmopstools.clu import CluClient
from lvmopstools.retrier import Retrier
from lvmopstools.utils import with_timeout

from lvmcryo.config import get_internal_config
from lvmcryo.handlers.thermistor import ThermistorHandler
Expand Down Expand Up @@ -93,7 +94,7 @@ async def valve_on_off(

if on is True and isinstance(timeout, (int, float)) and use_script is True:
# First we need to get the outlet number.
info = await outlet_info(actor, outlet_name)
info = await with_timeout(outlet_info(actor, outlet_name), timeout=5)
id_ = info["id"]

command_string = f"scripts run cycle_with_timeout {id_} {timeout}"
Expand Down Expand Up @@ -148,11 +149,14 @@ async def close_all_valves(config: Configuration | None = None, dry_run: bool =

await asyncio.gather(
*[
valve_on_off(
valve_info[valve]["actor"],
valve_info[valve]["outlet"],
False,
dry_run=dry_run,
with_timeout(
valve_on_off(
valve_info[valve]["actor"],
valve_info[valve]["outlet"],
False,
dry_run=dry_run,
),
timeout=10,
)
for valve in valve_info
]
Expand Down Expand Up @@ -210,7 +214,7 @@ async def check(self):
"""Check the connection to the NPS."""

try:
info = await outlet_info(self.actor, self.outlet)
info = await with_timeout(outlet_info(self.actor, self.outlet), timeout=5)
assert isinstance(info, dict), "Invalid outlet info."
assert not info["state"], "Valve is already open."
except Exception as err:
Expand Down

0 comments on commit 2d0684a

Please sign in to comment.