Skip to content

Commit

Permalink
Fix signal handling in Multiprocess class
Browse files Browse the repository at this point in the history
  • Loading branch information
abersheeran committed Dec 15, 2023
1 parent c602782 commit c41e48d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions uvicorn/supervisors/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def run(self) -> None:
self.handle_signals()
self.keep_subprocess_alive()

self.terminate_all()
self.join_all()

message = "Stopping parent process [{}]".format(os.getpid())
Expand Down Expand Up @@ -199,15 +200,19 @@ def handle_signals(self) -> None:

def handle_int(self) -> None:
logger.info("Received SIGINT, exiting")
self.should_exit.set()
self.keep_alive_checking.wait()
self.terminate_all()
if not self.should_exit.is_set():
self.should_exit.set()
else:
self.keep_alive_checking.wait()
self.terminate_all()

def handle_term(self) -> None:
logger.info("Received SIGTERM, exiting")
self.should_exit.set()
self.keep_alive_checking.wait()
self.terminate_all()
if not self.should_exit.is_set():
self.should_exit.set()
else:
self.keep_alive_checking.wait()
self.terminate_all()

def handle_break(self) -> None:
logger.info("Received SIGBREAK, exiting")
Expand Down

0 comments on commit c41e48d

Please sign in to comment.