From 0d712196667f0dc89663c3ad46930fd06f3cc588 Mon Sep 17 00:00:00 2001 From: Kent Bull Date: Sun, 12 Jan 2025 20:54:21 -0700 Subject: [PATCH] refactor: remove redundant SigInt handler Since the Doist loop listens for the KeyboardInterrupt exception then it effectively handles the Ctrl-C SigInt interrupt already which means the shutdown handler only has to handle the SigTerm signal. --- src/vlei/app/shutdown.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/vlei/app/shutdown.py b/src/vlei/app/shutdown.py index ad3f90e..2fcfd9d 100644 --- a/src/vlei/app/shutdown.py +++ b/src/vlei/app/shutdown.py @@ -8,8 +8,8 @@ class GracefulShutdownDoer(doing.Doer): """ Shuts all Agency agents down before exiting the Doist loop, performing a graceful shutdown. - Sets up signal handlers in the Doer.enter lifecycle method and exits the Doist scheduler loop in Doer.exit - Checks for the signals in the Doer.recur lifecycle method. + Sets up signal handler in the Doer.enter lifecycle method and exits the Doist scheduler loop in Doer.exit + Checks for the shutdown flag in the Doer.recur lifecycle method. """ def __init__(self, doist, **kwa): """ @@ -27,11 +27,6 @@ def handle_sigterm(self, signum, frame): logger.info(f"Received SIGTERM, initiating graceful shutdown.") self.shutdown_received = True - def handle_sigint(self, signum, frame): - """Handler function for SIGINT""" - logger.info(f"Received SIGINT, initiating graceful shutdown.") - self.shutdown_received = True - def enter(self): """ Sets up signal handlers. @@ -39,7 +34,6 @@ def enter(self): """ # Register signal handler signal.signal(signal.SIGTERM, self.handle_sigterm) - signal.signal(signal.SIGINT, self.handle_sigint) logger.info("Registered signal handlers for SIGTERM and SIGINT") def recur(self, tock=0.0):