Skip to content

Commit

Permalink
♲Wire server termination through interrupt setter
Browse files Browse the repository at this point in the history
This has a benefit of consolidating the server teardown code.
  • Loading branch information
webknjaz committed Mar 23, 2024
1 parent 3f20bc7 commit 029600e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cheroot/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1729,12 +1729,16 @@ def safe_start(self):
"""Run the server forever, and stop it cleanly on exit."""
try:
self.start()
except KeyboardInterrupt:
self.stop()
raise
except SystemExit:
self.stop()
raise
except KeyboardInterrupt as kb_intr_exc:
underlying_interrupt = self.interrupt
if not underlying_interrupt:
self.interrupt = kb_intr_exc
raise kb_intr_exc from underlying_interrupt
except SystemExit as sys_exit_exc:
underlying_interrupt = self.interrupt
if not underlying_interrupt:
self.interrupt = sys_exit_exc
raise sys_exit_exc from underlying_interrupt

def prepare(self): # noqa: C901 # FIXME
"""Prepare server to serving requests.
Expand Down

0 comments on commit 029600e

Please sign in to comment.