Update subprocess.run usage

This commit is contained in:
awsr
2026-03-05 20:06:09 -08:00
parent af8622240c
commit feffbe0851
4 changed files with 10 additions and 11 deletions
+2 -3
View File
@@ -13,9 +13,8 @@ def get_nvidia_smi(output='dict'):
if smi is None:
log.error("nvidia-smi not found")
return None
result = subprocess.run(f'"{smi}" -q -x', shell=True, check=False, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
xml = result.stdout.decode(encoding="utf8", errors="ignore")
d = xmltodict.parse(xml)
result = subprocess.run(f'"{smi}" -q -x', shell=True, check=False, env=os.environ, capture_output=True, text=True)
d = xmltodict.parse(result.stdout)
if 'nvidia_smi_log' in d:
d = d['nvidia_smi_log']
if 'gpu' in d and 'supported_clocks' in d['gpu']:
+4 -4
View File
@@ -97,13 +97,13 @@ def run(command, desc=None, errdesc=None, custom_env=None, live=False): # compat
if result.returncode != 0:
raise RuntimeError(f"""{errdesc or 'Error running command'} Command: {command} Error code: {result.returncode}""")
return ''
result = subprocess.run(command, capture_output=True, check=False, shell=True, env=os.environ if custom_env is None else custom_env)
result = subprocess.run(command, capture_output=True, check=False, shell=True, env=os.environ if custom_env is None else custom_env, text=True)
if result.returncode != 0:
raise RuntimeError(f"""{errdesc or 'Error running command'}: {command} code: {result.returncode}
{result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else ''}
{result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else ''}
{result.stdout}
{result.stderr}
""")
return result.stdout.decode(encoding="utf8", errors="ignore")
return result.stdout
def check_run(command): # compatbility function
+2 -2
View File
@@ -104,8 +104,8 @@ def get_gpu_info():
elif torch.cuda.is_available() and torch.version.cuda:
try:
import subprocess
result = subprocess.run('nvidia-smi --query-gpu=driver_version --format=csv,noheader', shell=True, check=False, env=os.environ, capture_output=True)
version = result.stdout.decode(encoding="utf8", errors="ignore").strip()
result = subprocess.run('nvidia-smi --query-gpu=driver_version --format=csv,noheader', shell=True, check=False, env=os.environ, capture_output=True, text=True)
version = result.stdout.strip()
return version
except Exception:
return ''
+2 -2
View File
@@ -31,8 +31,8 @@ def dirname(path_: str, r: int = 1) -> str:
def spawn(command: str | list[str], cwd: os.PathLike = '.') -> str:
process = subprocess.run(command, cwd=cwd, shell=True, check=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
return process.stdout.decode(encoding="utf8", errors="ignore")
process = subprocess.run(command, cwd=cwd, shell=True, check=False, capture_output=True, text=True)
return process.stdout
def load_library_global(path_: str):