Make utils.cpu_count() even more failsafe on Windows

This commit is contained in:
Moritz Brückner 2021-11-07 16:48:46 +01:00
parent 6bb2513001
commit 1430e22a90
1 changed files with 2 additions and 1 deletions

View File

@ -1167,7 +1167,8 @@ def cpu_count(*, physical_only=False) -> Optional[int]:
_os = get_os()
try:
if _os == 'win':
command = [f'{os.environ.get("SYSTEMROOT")}\\System32\\wbem\\wmic.exe', 'cpu', 'get', 'NumberOfCores']
sysroot = os.environ.get("SYSTEMROOT", default="C:\\WINDOWS")
command = [f'{sysroot}\\System32\\wbem\\wmic.exe', 'cpu', 'get', 'NumberOfCores']
result = subprocess.check_output(command)
result = result.decode('utf-8').splitlines()
result = int(result[2])