Skip to content

Commit

Permalink
Improve handling of keyboard interrupt during post-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Oct 7, 2024
1 parent 078e0fc commit c6908bc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 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

* Improve handling of keyboard interrupt during post-processing.


## 0.1.6 - 2024-09-26

### ✨ Improved
Expand Down
4 changes: 4 additions & 0 deletions src/lvmcryo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ async def ln2(
log.info(f"LN2 {action.value} completed successfully.")

finally:
# At this point all the valves are closed so we can remove the signal handlers.
for signame in ("SIGINT", "SIGTERM"):
asyncio.get_running_loop().remove_signal_handler(getattr(signal, signame))

handler.event_times.end_time = get_now()
await handler.clear()

Expand Down
24 changes: 17 additions & 7 deletions src/lvmcryo/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import pathlib
import signal
import sys
from datetime import datetime, timedelta

from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -49,6 +50,9 @@ 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.")
sys.exit(1)


async def ln2_runner(
handler: LN2Handler,
Expand Down Expand Up @@ -214,15 +218,21 @@ async def post_fill_tasks(

if write_data and event_times.start_time and event_times.end_time:
if data_extra_time:
log.info(f"Waiting {data_extra_time} seconds before collecting data.")

if notifier is not None:
await notifier.post_to_slack(
f"Fill notifications will be delayed {data_extra_time:.0f} "
"seconds while collecting post-fill data."
if handler.aborted or handler.failed:
log.warning(
"Fill was aborted or failed. Not waiting "
"additional time to collect data."
)
else:
log.info(f"Waiting {data_extra_time} seconds before collecting data.")

if notifier is not None:
await notifier.post_to_slack(
f"Fill notifications will be delayed {data_extra_time:.0f} "
"seconds while collecting post-fill data."
)

await asyncio.sleep(data_extra_time)
await asyncio.sleep(data_extra_time)

if data_path is None:
data_path = pathlib.Path.cwd() / "fill_data.parquet"
Expand Down

0 comments on commit c6908bc

Please sign in to comment.