From c80e04ab0be9156e11df7bf0aaa1bc1ee5655db8 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Tue, 17 Feb 2026 19:10:13 -0600 Subject: [PATCH] chore: add signal handling for graceful shutdown and fix typo - Implemented SIGTERM and SIGINT handlers in ServerController for better container support. - Fixed 'occured' typo in ClientDownloading. --- hydrus/client/ClientDownloading.py | 8 ++++---- hydrus/server/ServerController.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hydrus/client/ClientDownloading.py b/hydrus/client/ClientDownloading.py index a622c6324..4e73dd773 100644 --- a/hydrus/client/ClientDownloading.py +++ b/hydrus/client/ClientDownloading.py @@ -273,7 +273,7 @@ def _DoMainLoop( self ): try: - errors_occured = [] + errors_occurred = [] file_successful = False media_result = self._controller.Read( 'media_result', hash ) @@ -347,7 +347,7 @@ def _DoMainLoop( self ): except Exception as e: - errors_occured.append( e ) + errors_occurred.append( e ) @@ -356,11 +356,11 @@ def _DoMainLoop( self ): total_successful_hashes_in_this_run += 1 - if len( errors_occured ) > 0: + if len( errors_occurred ) > 0: if not file_successful: - raise errors_occured[0] + raise errors_occurred[0] diff --git a/hydrus/server/ServerController.py b/hydrus/server/ServerController.py index bb03ea4a3..653e0c9ce 100644 --- a/hydrus/server/ServerController.py +++ b/hydrus/server/ServerController.py @@ -1,4 +1,5 @@ import os +import signal import requests import time import traceback @@ -390,6 +391,9 @@ def Run( self ): HydrusData.Print( 'Server is running. Press Ctrl+C to quit.' ) + signal.signal( signal.SIGTERM, self.CatchSignal ) + signal.signal( signal.SIGINT, self.CatchSignal ) + try: while not HG.model_shutdown and not self._shutdown: @@ -605,6 +609,14 @@ def ShutdownView( self ): HydrusController.HydrusController.ShutdownView( self ) + def CatchSignal( self, sig, frame ): + + if sig in ( signal.SIGTERM, signal.SIGINT ): + + self.ShutdownFromServer() + + + def ShutdownFromServer( self ): HydrusData.Print( 'Received a server shut down request' + HC.UNICODE_ELLIPSIS )