Clean vLLM process groups after parent exit
This commit is contained in:
@@ -401,27 +401,37 @@ def _wait_for_server_or_exit(
|
||||
raise HttpClientError(f"Timed out waiting for {base_url}{healthcheck_path}: {last_error}")
|
||||
|
||||
|
||||
def _process_group_exists(pgid: int) -> bool:
|
||||
try:
|
||||
os.killpg(pgid, 0)
|
||||
return True
|
||||
except ProcessLookupError:
|
||||
return False
|
||||
|
||||
|
||||
def _terminate_process_tree(process: subprocess.Popen[str], *, timeout_s: float = 30.0) -> None:
|
||||
if process.poll() is not None:
|
||||
return
|
||||
try:
|
||||
pgid = os.getpgid(process.pid)
|
||||
except ProcessLookupError:
|
||||
return
|
||||
# Children can keep the session/process group alive after the vLLM API
|
||||
# server exits. In that case the group id is still the original pid
|
||||
# because the process was launched with start_new_session=True.
|
||||
pgid = process.pid
|
||||
try:
|
||||
os.killpg(pgid, signal.SIGTERM)
|
||||
except ProcessLookupError:
|
||||
return
|
||||
deadline = time.monotonic() + timeout_s
|
||||
while time.monotonic() < deadline:
|
||||
if process.poll() is not None:
|
||||
if not _process_group_exists(pgid):
|
||||
return
|
||||
time.sleep(0.1)
|
||||
try:
|
||||
os.killpg(pgid, signal.SIGKILL)
|
||||
except ProcessLookupError:
|
||||
return
|
||||
process.wait(timeout=timeout_s)
|
||||
if process.poll() is None:
|
||||
process.wait(timeout=timeout_s)
|
||||
|
||||
|
||||
def run_trial(trial_spec_path: Path) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user