From 54470d9485fdb46452f9b4e2cf464f8708c360d9 Mon Sep 17 00:00:00 2001 From: Joan Fontanals Martinez Date: Fri, 18 Nov 2022 10:44:14 +0100 Subject: [PATCH] feat: compose already existing signal handling Signed-off-by: Joan Fontanals Martinez --- uvicorn/server.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/uvicorn/server.py b/uvicorn/server.py index 99308b397..53479ab6e 100644 --- a/uvicorn/server.py +++ b/uvicorn/server.py @@ -292,9 +292,19 @@ def install_signal_handlers(self) -> None: loop = asyncio.get_event_loop() + def _composed_handler(previous_handler): + def _inner_handler(*args, **kwargs): + previous_handler(*args, **kwargs) + self.handle_exit(*args, **kwargs) + + return _inner_handler + try: for sig in HANDLED_SIGNALS: - loop.add_signal_handler(sig, self.handle_exit, sig, None) + handler = loop._signal_handlers[sig] + if handler is not None: + handler = _composed_handler(handler) + loop.add_signal_handler(sig, handler, sig, None) except NotImplementedError: # pragma: no cover # Windows for sig in HANDLED_SIGNALS: