From dd719e1039473d0a556fafb8bd7f271bc4ff6c5e Mon Sep 17 00:00:00 2001 From: Altan Orhon Date: Thu, 28 Sep 2023 14:28:09 -0700 Subject: [PATCH] Signal handling --- hyakvnc/__main__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hyakvnc/__main__.py b/hyakvnc/__main__.py index c184856..62db73e 100644 --- a/hyakvnc/__main__.py +++ b/hyakvnc/__main__.py @@ -40,7 +40,7 @@ def cmd_create(container_path: Union[str, Path], dry_run=False) -> Union[HyakVnc :return: None """ - def kill_self(sig=signal.SIGSTOP): + def kill_self(sig=signal.SIGTERM): os.kill(os.getpid(), sig) def cancel_created_jobs(): @@ -62,7 +62,9 @@ def create_node_signal_handler(signal_number, frame): exit(1) signal.signal(signal.SIGINT, create_node_signal_handler) - signal.signal(signal.SIGTSTP, create_node_signal_handler) + signal.signal(signal.SIGSTOP, create_node_signal_handler) + signal.signal(signal.SIGTERM, create_node_signal_handler) + container_path = Path(container_path) container_name = container_path.stem @@ -209,7 +211,9 @@ def signal_handler(signal_number, frame): exit(1) signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTSTP, signal_handler) + signal.signal(signal.SIGSTOP, signal_handler) + signal.signal(signal.SIGTERM, signal_handler) + logger.info("Finding running VNC jobs...") vnc_sessions = HyakVncSession.find_running_sessions(app_config) @@ -231,7 +235,9 @@ def signal_handler(signal_number, frame): exit(1) signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTSTP, signal_handler) + signal.signal(signal.SIGSTOP, signal_handler) + signal.signal(signal.SIGTERM, signal_handler) + assert (job_id is not None) ^ (session is not None), "Must specify either a job id or session"