Skip to content

Commit

Permalink
main: still use sys.exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Nov 27, 2024
1 parent 66ae925 commit 732b5e1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/otaclient/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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()

0 comments on commit 732b5e1

Please sign in to comment.