Skip to content

Commit

Permalink
Try to close as many LN2 valves as possible before failing
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jan 9, 2025
1 parent 4a34077 commit 24662f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Next version

### ✨ Improved

* Try to close as many LN2 valves as possible before failing


## 0.3.7 - 2025-01-09

### ✨ Improved
Expand Down
7 changes: 6 additions & 1 deletion src/lvmcryo/handlers/ln2.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,12 @@ async def close_valves(self, only_active: bool = True):
if valve_handler.active or not only_active:
tasks.append(valve_handler.finish())

await asyncio.gather(*tasks)
# Try to close as many valves as possible but then raise the error if
# any failed.
results = await asyncio.gather(*tasks, return_exceptions=True)
for result in results:
if isinstance(result, Exception):
raise result

async def clear(self):
"""Cleanly finishes tasks and other clean-up tasks."""
Expand Down
8 changes: 6 additions & 2 deletions src/lvmcryo/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ async def signal_handler(handler: LN2Handler, log: logging.Logger):
"""Handles signals to close all valves and exit cleanly."""

log.error("User aborted the process. Closing all valves before exiting.")
await handler.close_valves(only_active=False)
try:
await handler.close_valves(only_active=False)
except Exception as err:
log.error(f"Failed closing LN2 valves: {err!r}")

await handler.clear()

handler.failed = True
Expand All @@ -51,7 +55,7 @@ async def signal_handler(handler: LN2Handler, log: logging.Logger):
handler.event_times.abort_time = get_now()
handler.event_times.end_time = get_now()

log.error("Exiting now. Not data or notifications will be sent.")
log.error("Exiting now. No data or notifications will be sent.")
sys.exit(1)


Expand Down

0 comments on commit 24662f6

Please sign in to comment.