[BugFix] Enforce C locale for CPU binding subprocess parsing (#8261)
### What this PR does / why we need it? This PR backports the CPU binding locale normalization fix from #7274 to `releases/v0.18.0`, including the follow-up review fixes already applied on `main`. The change forces `LC_ALL`, `LANG`, and `LC_MESSAGES` to `C` before spawning subprocesses in `vllm_ascend.cpu_binding.execute_command()`, so parser-dependent command output stays stable on localized systems. It also handles `subprocess.TimeoutExpired` by killing the child process before collecting output, and updates the existing unit tests to keep command-argument coverage while adding timeout-path coverage. Fixes #6992 ### Does this PR introduce _any_ user-facing change? Yes. Users running CPU binding on non-English OS environments should now get consistent English subprocess output for parser-dependent commands, avoiding failures caused by inherited locale settings. ### How was this patch tested? - Updated the existing unit tests in `tests/ut/device_allocator/test_cpu_binding.py` to assert the locale environment, retain command argument coverage, and cover the timeout cleanup path. - Attempted to run targeted pytest cases locally, but the pytest invocation did not complete normally in this environment, so I could not record a clean passing run here. Attribution: - Co-authored-by: stdjhs <1601599324@qq.com> - Signed-off-by: chenchuw886 <chenchuw@huawei.com> Signed-off-by: chenchuw886 <chenchuw@huawei.com> Co-authored-by: chenchuw886 <chenchuw@huawei.com> Co-authored-by: stdjhs <1601599324@qq.com>
This commit is contained in:
@@ -37,8 +37,17 @@ def is_arm_cpu() -> bool:
|
||||
|
||||
|
||||
def execute_command(cmd: list[str]) -> tuple[str, int]:
|
||||
with subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
|
||||
out, _ = p.communicate(timeout=1000)
|
||||
# Force a C locale so subprocess output remains parseable on localized OSes.
|
||||
env = os.environ.copy()
|
||||
env["LC_ALL"] = "C"
|
||||
env["LANG"] = "C"
|
||||
env["LC_MESSAGES"] = "C"
|
||||
with subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) as p:
|
||||
try:
|
||||
out, _ = p.communicate(timeout=1000)
|
||||
except subprocess.TimeoutExpired:
|
||||
p.kill()
|
||||
out, _ = p.communicate()
|
||||
return out.decode(), p.returncode
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user