[Bugfix] Make suppress_stdout redirect fd 1 instead of sys.stdout.fileno() (#59336)
Signed-off-by: usmanmateen <usmanmateen255@gmail.com> Co-authored-by: Misha Goin <mgoin64@gmail.com>
This commit is contained in:
co-authored by
Misha Goin
parent
dfaabf91ac
commit
e73895a5df
@@ -1,11 +1,18 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
|
import contextlib
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from vllm.utils.system_utils import _maybe_force_spawn, unique_filepath
|
from vllm.utils.system_utils import (
|
||||||
|
_maybe_force_spawn,
|
||||||
|
suppress_stdout,
|
||||||
|
unique_filepath,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_unique_filepath():
|
def test_unique_filepath():
|
||||||
@@ -25,3 +32,19 @@ def test_numa_bind_forces_spawn(monkeypatch):
|
|||||||
monkeypatch.setattr("sys.argv", ["vllm", "serve", "--numa-bind"])
|
monkeypatch.setattr("sys.argv", ["vllm", "serve", "--numa-bind"])
|
||||||
_maybe_force_spawn()
|
_maybe_force_spawn()
|
||||||
assert os.environ["VLLM_WORKER_MULTIPROC_METHOD"] == "spawn"
|
assert os.environ["VLLM_WORKER_MULTIPROC_METHOD"] == "spawn"
|
||||||
|
|
||||||
|
|
||||||
|
def test_suppress_stdout_when_sys_stdout_has_no_fd(capfd):
|
||||||
|
with contextlib.redirect_stdout(io.StringIO()), suppress_stdout():
|
||||||
|
os.write(1, b"c library output\n")
|
||||||
|
assert "c library output" not in capfd.readouterr().out
|
||||||
|
|
||||||
|
|
||||||
|
def test_suppress_stdout_keeps_stderr_when_sys_stdout_is_stderr(capfd, monkeypatch):
|
||||||
|
monkeypatch.setattr(sys, "stdout", sys.stderr)
|
||||||
|
with suppress_stdout():
|
||||||
|
os.write(1, b"c library output\n")
|
||||||
|
os.write(sys.stderr.fileno(), b"error message\n")
|
||||||
|
out, err = capfd.readouterr()
|
||||||
|
assert "c library output" not in out
|
||||||
|
assert "error message" in err
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ def suppress_stdout():
|
|||||||
yield
|
yield
|
||||||
return
|
return
|
||||||
|
|
||||||
stdout_fd = sys.stdout.fileno()
|
# C libraries write to fd 1, whatever sys.stdout is bound to.
|
||||||
|
stdout_fd = 1
|
||||||
stdout_dup = os.dup(stdout_fd)
|
stdout_dup = os.dup(stdout_fd)
|
||||||
devnull_fd = os.open(os.devnull, os.O_WRONLY)
|
devnull_fd = os.open(os.devnull, os.O_WRONLY)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user