diff --git a/cli/nvidia-smi.py b/cli/nvidia-smi.py index 37d6390c5..298fc562e 100755 --- a/cli/nvidia-smi.py +++ b/cli/nvidia-smi.py @@ -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']: diff --git a/launch.py b/launch.py index 6664be77b..a3d503293 100755 --- a/launch.py +++ b/launch.py @@ -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 diff --git a/modules/devices.py b/modules/devices.py index 99276e30e..90f86ffcb 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -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 '' diff --git a/modules/rocm.py b/modules/rocm.py index 7295b4a52..576686d18 100644 --- a/modules/rocm.py +++ b/modules/rocm.py @@ -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):