From 732b5e18c7ac6e8f04b02b4c7136f291ae32ca90 Mon Sep 17 00:00:00 2001 From: "bodong.yang" Date: Wed, 27 Nov 2024 02:27:15 +0000 Subject: [PATCH] main: still use sys.exit --- src/otaclient/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/otaclient/main.py b/src/otaclient/main.py index 289b06799..1778e68fc 100644 --- a/src/otaclient/main.py +++ b/src/otaclient/main.py @@ -23,6 +23,7 @@ import multiprocessing.shared_memory as mp_shm import secrets import signal +import sys import threading import time from functools import partial @@ -44,7 +45,7 @@ _shm: mp_shm.SharedMemory | None = None -def _on_shutdown(): +def _on_shutdown(sys_exit: bool = False): global _ota_core_p, _grpc_server_p, _shm if _ota_core_p: _ota_core_p.terminate() @@ -61,10 +62,13 @@ def _on_shutdown(): _shm.unlink() _shm = None + if sys_exit: + sys.exit(1) + def _signal_handler(signal_value, _) -> None: print(f"otaclient receives {signal_value=}, shutting down ...") - _on_shutdown() + _on_shutdown(sys_exit=True) def main() -> None: @@ -157,11 +161,11 @@ def main() -> None: f"otaclient will exit in {SHUTDOWN_AFTER_CORE_EXIT}seconds ..." ) time.sleep(SHUTDOWN_AFTER_CORE_EXIT) - _on_shutdown() + return _on_shutdown() if not _grpc_server_p.is_alive(): logger.error( f"ota API server is dead, whole otaclient will exit in {SHUTDOWN_AFTER_API_SERVER_EXIT}seconds ..." ) time.sleep(SHUTDOWN_AFTER_API_SERVER_EXIT) - _on_shutdown() + return _on_shutdown()