Skip to content

Commit

Permalink
refactor: remove redundant SigInt handler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kentbull committed Jan 13, 2025
1 parent 42ac5c8 commit b722e09
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/keria/app/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 being set in the Doer.recur lifecycle method.
"""
def __init__(self, doist, agency, **kwa):
"""
Expand All @@ -29,11 +29,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 shutdown_agents(self, agents):
"""Helper function to shut down the agents."""
logger.info("Stopping %s agents", len(agents))
Expand All @@ -47,8 +42,7 @@ 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")
logger.info("Registered signal handlers for SIGTERM")

def recur(self, tock=0.0):
"""Generator coroutine checking once per tock for shutdown flag"""
Expand Down

0 comments on commit b722e09

Please sign in to comment.