From 9be4c1771b68ae395baad8b14e5ad810602c5fbc Mon Sep 17 00:00:00 2001 From: abersheeran Date: Tue, 25 Jun 2024 15:24:20 +0800 Subject: [PATCH 1/3] feat: Improve process termination logic in multiprocess manager --- uvicorn/supervisors/multiprocess.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/uvicorn/supervisors/multiprocess.py b/uvicorn/supervisors/multiprocess.py index c242fed9a..30e897582 100644 --- a/uvicorn/supervisors/multiprocess.py +++ b/uvicorn/supervisors/multiprocess.py @@ -90,9 +90,13 @@ def kill(self) -> None: # In Unix, the method will send SIGKILL to the process. self.process.kill() - def join(self) -> None: + def join(self, join_timeout: float | None = None) -> None: logger.info(f"Waiting for child process [{self.process.pid}]") - self.process.join() + self.process.join(join_timeout) + # Timeout, kill the process + while self.process.exitcode is None: + self.process.kill() + self.process.join(1) @property def pid(self) -> int | None: @@ -131,7 +135,7 @@ def terminate_all(self) -> None: def join_all(self) -> None: for process in self.processes: - process.join() + process.join(self.config.timeout_graceful_shutdown) def restart_all(self) -> None: for idx, process in enumerate(tuple(self.processes)): From da67e212077a1a90689f400b2c150c0d92bc4055 Mon Sep 17 00:00:00 2001 From: Aber Date: Fri, 27 Sep 2024 15:52:10 +0800 Subject: [PATCH 2/3] Update uvicorn/supervisors/multiprocess.py Co-authored-by: Marcelo Trylesinski --- uvicorn/supervisors/multiprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uvicorn/supervisors/multiprocess.py b/uvicorn/supervisors/multiprocess.py index 30e897582..5455d4744 100644 --- a/uvicorn/supervisors/multiprocess.py +++ b/uvicorn/supervisors/multiprocess.py @@ -90,7 +90,7 @@ def kill(self) -> None: # In Unix, the method will send SIGKILL to the process. self.process.kill() - def join(self, join_timeout: float | None = None) -> None: + def join(self, timeout: float | None = None) -> None: logger.info(f"Waiting for child process [{self.process.pid}]") self.process.join(join_timeout) # Timeout, kill the process From 4fc41f94e1611ad4742aa35f7960f96f11286383 Mon Sep 17 00:00:00 2001 From: Aber Date: Fri, 27 Sep 2024 15:55:06 +0800 Subject: [PATCH 3/3] fix name changed --- uvicorn/supervisors/multiprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uvicorn/supervisors/multiprocess.py b/uvicorn/supervisors/multiprocess.py index d436775a1..e0395f1cc 100644 --- a/uvicorn/supervisors/multiprocess.py +++ b/uvicorn/supervisors/multiprocess.py @@ -92,7 +92,7 @@ def kill(self) -> None: def join(self, timeout: float | None = None) -> None: logger.info(f"Waiting for child process [{self.process.pid}]") - self.process.join(join_timeout) + self.process.join(timeout) # Timeout, kill the process while self.process.exitcode is None: self.process.kill()