You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 13:52:00 +01:00
better exit mechanic
This commit is contained in:
@@ -24,6 +24,7 @@ MODULES_DIR = Path(__file__, "..", MODULES_PACKAGE).resolve()
|
|||||||
logger = log95.log95("CORE")
|
logger = log95.log95("CORE")
|
||||||
|
|
||||||
exit_pending = False
|
exit_pending = False
|
||||||
|
exit_status_code = 0
|
||||||
intr_time = 0
|
intr_time = 0
|
||||||
exit_lock = threading.Lock()
|
exit_lock = threading.Lock()
|
||||||
|
|
||||||
@@ -81,17 +82,18 @@ class ProcessManager(Skeleton_ProcessManager):
|
|||||||
procman = ProcessManager()
|
procman = ProcessManager()
|
||||||
|
|
||||||
def handle_sigint(signum, frame):
|
def handle_sigint(signum, frame):
|
||||||
global exit_pending, intr_time
|
global exit_pending, intr_time, exit_status_code
|
||||||
with exit_lock:
|
with exit_lock:
|
||||||
logger.info("Received SIGINT")
|
logger.info("Received SIGINT")
|
||||||
if (time.monotonic() - intr_time) > 5:
|
if (time.monotonic() - intr_time) > 5:
|
||||||
intr_time = time.monotonic()
|
intr_time = time.monotonic()
|
||||||
logger.info("Will quit on song end.")
|
logger.info("Will quit on song end.")
|
||||||
exit_pending = True
|
exit_pending = True
|
||||||
|
exit_status_code = 130
|
||||||
else:
|
else:
|
||||||
logger.warning("Force-Quit pending")
|
logger.warning("Force-Quit pending")
|
||||||
procman.stop_all()
|
procman.stop_all()
|
||||||
raise SystemExit
|
raise SystemExit(130)
|
||||||
signal.signal(signal.SIGINT, handle_sigint)
|
signal.signal(signal.SIGINT, handle_sigint)
|
||||||
|
|
||||||
def load_filelines(path: Path):
|
def load_filelines(path: Path):
|
||||||
@@ -170,7 +172,7 @@ def play_playlist(playlist_path: Path, starting_index: int = 0):
|
|||||||
if exit_pending:
|
if exit_pending:
|
||||||
logger.info("Quit received, waiting for song end.")
|
logger.info("Quit received, waiting for song end.")
|
||||||
procman.wait_all()
|
procman.wait_all()
|
||||||
raise SystemExit
|
raise SystemExit(exit_status_code)
|
||||||
elif return_pending:
|
elif return_pending:
|
||||||
logger.info("Return reached, next song will reload the playlist.")
|
logger.info("Return reached, next song will reload the playlist.")
|
||||||
procman.wait_all()
|
procman.wait_all()
|
||||||
@@ -275,7 +277,7 @@ def main():
|
|||||||
if playlist := playlist_advisor.advise(arg):
|
if playlist := playlist_advisor.advise(arg):
|
||||||
logger.info(f"Advisor picked '{playlist}' to play")
|
logger.info(f"Advisor picked '{playlist}' to play")
|
||||||
play_playlist(playlist)
|
play_playlist(playlist)
|
||||||
if exit_pending: raise SystemExit
|
if exit_pending: raise SystemExit(exit_status_code)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical_error(f"Unexpected error: {e}")
|
logger.critical_error(f"Unexpected error: {e}")
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user