From c23cd24e6676ee0638d014d7000af1e6e0996bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20K=C3=BChn?= Date: Fri, 28 Jun 2024 18:39:45 +0200 Subject: [PATCH] Iterate subprocesses in-place (#2373) * replace suprocesses inplace * list is not resized, no need for copying --- uvicorn/supervisors/multiprocess.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/uvicorn/supervisors/multiprocess.py b/uvicorn/supervisors/multiprocess.py index c242fed9a..fff6871fc 100644 --- a/uvicorn/supervisors/multiprocess.py +++ b/uvicorn/supervisors/multiprocess.py @@ -134,7 +134,7 @@ def join_all(self) -> None: process.join() def restart_all(self) -> None: - for idx, process in enumerate(tuple(self.processes)): + for idx, process in enumerate(self.processes): process.terminate() process.join() new_process = Process(self.config, self.target, self.sockets) @@ -163,7 +163,7 @@ def keep_subprocess_alive(self) -> None: if self.should_exit.is_set(): return # parent process is exiting, no need to keep subprocess alive - for idx, process in enumerate(tuple(self.processes)): + for idx, process in enumerate(self.processes): if process.is_alive(): continue @@ -174,10 +174,9 @@ def keep_subprocess_alive(self) -> None: return logger.info(f"Child process [{process.pid}] died") - del self.processes[idx] process = Process(self.config, self.target, self.sockets) process.start() - self.processes.append(process) + self.processes[idx] = process def handle_signals(self) -> None: for sig in tuple(self.signal_queue):