Skip to content

Commit

Permalink
feat: compose already existing signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Nov 18, 2022
1 parent 53d7d1e commit 56dce4b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion uvicorn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 56dce4b

Please sign in to comment.