From 0e6fe37e4d988bc568610cc09fcc92d5114e1d4c Mon Sep 17 00:00:00 2001 From: RodoMa92 Date: Wed, 28 Aug 2024 12:14:37 +0200 Subject: [PATCH 1/2] Properly handle systemd signals --- backend/decky_loader/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/decky_loader/main.py b/backend/decky_loader/main.py index c268b387..1c280453 100644 --- a/backend/decky_loader/main.py +++ b/backend/decky_loader/main.py @@ -11,6 +11,7 @@ # Full imports import multiprocessing multiprocessing.freeze_support() +import signal from asyncio import AbstractEventLoop, CancelledError, Task, all_tasks, current_task, gather, new_event_loop, set_event_loop, sleep from logging import basicConfig, getLogger from os import path @@ -258,6 +259,11 @@ def main(): # Append the system and user python paths sys.path.extend(get_system_pythonpaths()) + #Catch a sigint (CTRL-C) coming from systemd and shut down gracefully + #TODO: Handle the Windows case in the future + if ON_LINUX: + signal.signal(signal.SIGINT, PluginManager.shutdown) + logger.info(f"Starting Decky version {get_loader_version()}") loop = new_event_loop() From a5985c22222cf0b8d1acf6b79ab325df8af56d33 Mon Sep 17 00:00:00 2001 From: RodoMa92 Date: Wed, 28 Aug 2024 12:23:11 +0200 Subject: [PATCH 2/2] Second attempt at satisfying python --- backend/decky_loader/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/decky_loader/main.py b/backend/decky_loader/main.py index 1c280453..0a76aba3 100644 --- a/backend/decky_loader/main.py +++ b/backend/decky_loader/main.py @@ -245,6 +245,10 @@ async def inject_javascript(self, tab: Tab, first: bool=False, request: Request| def run(self): run_app(self.web_app, host=get_server_host(), port=get_server_port(), loop=self.loop, access_log=None, handle_signals=True, shutdown_timeout=40) +def handle_systemd(): + PluginManager.shutdown() + pass + def main(): setproctitle(f"Decky Loader {get_loader_version()} ({getproctitle()})") setthreadtitle("Decky Loader") @@ -262,7 +266,7 @@ def main(): #Catch a sigint (CTRL-C) coming from systemd and shut down gracefully #TODO: Handle the Windows case in the future if ON_LINUX: - signal.signal(signal.SIGINT, PluginManager.shutdown) + signal.signal(signal.SIGINT, handle_systemd) logger.info(f"Starting Decky version {get_loader_version()}")