Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve process termination logic in multiprocess manager #2371

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions uvicorn/supervisors/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, timeout: float | None = None) -> None:
logger.info(f"Waiting for child process [{self.process.pid}]")
self.process.join()
self.process.join(timeout)
# Timeout, kill the process
while self.process.exitcode is None:
self.process.kill()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why CI failed is that this is not covered by the test. But I don't know how to design a process that will be 100% stuck.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to add the pragma here.

self.process.join(1)

@property
def pid(self) -> int | None:
Expand Down Expand Up @@ -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(self.processes):
Expand Down
Loading