From 4e542f2b0d3395af54e8dc881e9a96f5b45de4b8 Mon Sep 17 00:00:00 2001 From: KubaPro010 <132459354+KubaPro010@users.noreply.github.com> Date: Sat, 8 Nov 2025 20:14:33 +0100 Subject: [PATCH] better exit mechanic --- radioPlayer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/radioPlayer.py b/radioPlayer.py index ab6403a..74b0296 100644 --- a/radioPlayer.py +++ b/radioPlayer.py @@ -24,6 +24,7 @@ MODULES_DIR = Path(__file__, "..", MODULES_PACKAGE).resolve() logger = log95.log95("CORE") exit_pending = False +exit_status_code = 0 intr_time = 0 exit_lock = threading.Lock() @@ -81,17 +82,18 @@ class ProcessManager(Skeleton_ProcessManager): procman = ProcessManager() def handle_sigint(signum, frame): - global exit_pending, intr_time + global exit_pending, intr_time, exit_status_code with exit_lock: logger.info("Received SIGINT") if (time.monotonic() - intr_time) > 5: intr_time = time.monotonic() logger.info("Will quit on song end.") exit_pending = True + exit_status_code = 130 else: logger.warning("Force-Quit pending") procman.stop_all() - raise SystemExit + raise SystemExit(130) signal.signal(signal.SIGINT, handle_sigint) def load_filelines(path: Path): @@ -170,7 +172,7 @@ def play_playlist(playlist_path: Path, starting_index: int = 0): if exit_pending: logger.info("Quit received, waiting for song end.") procman.wait_all() - raise SystemExit + raise SystemExit(exit_status_code) elif return_pending: logger.info("Return reached, next song will reload the playlist.") procman.wait_all() @@ -275,7 +277,7 @@ def main(): if playlist := playlist_advisor.advise(arg): logger.info(f"Advisor picked '{playlist}' to play") play_playlist(playlist) - if exit_pending: raise SystemExit + if exit_pending: raise SystemExit(exit_status_code) except Exception as e: logger.critical_error(f"Unexpected error: {e}") raise