Skip to content

Commit 3c833fd

Browse files
Enhance error handling in GracefulShutdownHandler
- Wrapped shutdown signal handling methods in try-except blocks to catch and handle exceptions gracefully. - Ensured that errors during shutdown processing are reported via the on_error method.
1 parent c7b764a commit 3c833fd

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

py_spring_core/core/interfaces/graceful_shutdown_handler.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,22 @@ def __init__(self) -> None:
3030
signal.signal(signal.SIGTERM, self._handle_sigterm)
3131

3232
def _handle_sigint(self, signum: int, frame: Optional[FrameType]) -> None:
33-
print("[Signal] SIGINT received")
34-
self._shutdown_type = ShutdownType.MANUAL
35-
self._shutdown_event.set()
36-
self.on_shutdown(ShutdownType.MANUAL)
33+
try:
34+
print("[Signal] SIGINT received")
35+
self._shutdown_type = ShutdownType.MANUAL
36+
self._shutdown_event.set()
37+
self.on_shutdown(ShutdownType.MANUAL)
38+
except Exception as error:
39+
self.on_error(error)
3740

3841
def _handle_sigterm(self, signum: int, frame: Optional[FrameType]) -> None:
39-
print("[Signal] SIGTERM received")
40-
self._shutdown_type = ShutdownType.SIGTERM
41-
self._shutdown_event.set()
42-
self.on_shutdown(ShutdownType.SIGTERM)
42+
try:
43+
print("[Signal] SIGTERM received")
44+
self._shutdown_type = ShutdownType.SIGTERM
45+
self._shutdown_event.set()
46+
self.on_shutdown(ShutdownType.SIGTERM)
47+
except Exception as error:
48+
self.on_error(error)
4349

4450

4551
def is_shutdown(self) -> bool:

0 commit comments

Comments
 (0)