Skip to content

Commit

Permalink
Iterate subprocesses in-place (#2373)
Browse files Browse the repository at this point in the history
* replace suprocesses inplace

* list is not resized, no need for copying
  • Loading branch information
maxfischer2781 authored Jun 28, 2024
1 parent d79f285 commit c23cd24
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions uvicorn/supervisors/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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):
Expand Down

0 comments on commit c23cd24

Please sign in to comment.