Fix #101873: wmic not found on insider builds of Windows 11 #101874

Merged
Sergey Sharybin merged 3 commits from xavierh/blender-open-data:xavierh-patch-1 into main 2024-09-30 17:26:53 +02:00
4 changed files with 77 additions and 32 deletions

View File

@ -128,37 +128,9 @@ def _get_cpu_topology() -> CPUTopology:
Get topology information (number of sockets, physical and logical threads)
of the system CPUs.
"""
sockets: int
cores: int
if not sys.platform.startswith('win'):
cores_info = cpu_cores.CPUCoresCounter.factory() # type: ignore
sockets = cores_info.get_physical_processors_count()
cores = cores_info.get_physical_cores_count()
else:
sockets = int(
subprocess.check_output(
(
'wmic',
'computersystem',
'get',
'NumberOfProcessors',
'/value',
),
text=True,
)
.strip()
.split('=')[1]
)
cores = sum(
int(line.strip().split('=')[1])
for line in subprocess.check_output(
('wmic', 'cpu', 'get', 'NumberOfCores', '/value'), text=True
)
.strip()
.split('\n')
if line.strip()
)
cores_info = cpu_cores.CPUCoresCounter.factory() # type: ignore
sockets: int = cores_info.get_physical_processors_count()
cores: int = cores_info.get_physical_cores_count()
return CPUTopology(sockets=sockets, cores=cores, threads=multiprocessing.cpu_count())

View File

@ -1,7 +1,7 @@
# This file is part of cpu_cores released under the MIT license.
# See the LICENSE file for more information.
version_info = (0, 1, 3)
version_info = (0, 1, 4)
__version__ = ".".join([str(x) for x in version_info])
from .common import CPUCoresCounter

View File

@ -25,6 +25,9 @@ class CPUCoresCounter(object):
elif cls.platform.startswith('linux'):
from .linux import LinuxCPUCoresCounter
return LinuxCPUCoresCounter()
elif cls.platform.startswith('win'):
from .windows import WindowsCPUCoresCounter
return WindowsCPUCoresCounter()
else:
raise NotImplementedError("unsupported platform type [%s]" %
cls.platform)

View File

@ -0,0 +1,70 @@
# This file is part of cpu_cores released under the MIT license.
# See the LICENSE file for more information.
import platform
import sys
import subprocess
from .common import CPUCoresCounter
class WindowsCPUCoresCounter(CPUCoresCounter):
def _count(self, cpuinfo_filepath=None):
# powershell is available from Windows 10, wmic is optional from Windows 11 2024
if sys.getwindowsversion().major >= 10:
processors = int(
subprocess.check_output(
(
'powershell',
'-Command',
'Get-CimInstance Win32_ComputerSystem | Select-Object -ExpandProperty NumberOfProcessors'
),
text=True,
)
.strip()
)
cores = sum(
int(core) for core in subprocess.check_output(
(
'powershell',
'-Command',
'Get-CimInstance Win32_Processor | Select-Object -ExpandProperty NumberOfCores'
),
text=True
)
.strip()
.split('\n')
if core
)
else:
processors = int(
subprocess.check_output(
(
'wmic',
'computersystem',
'get',
'NumberOfProcessors',
'/value',
),
text=True,
)
.strip()
.split('=')[1]
)
cores = sum(
int(line.strip().split('=')[1])
for line in subprocess.check_output(
('wmic', 'cpu', 'get', 'NumberOfCores', '/value'), text=True
)
.strip()
.split('\n')
if line.strip()
)
if cores == 0 or processors == 0:
raise Exception("can't get the cpu cores count (windows)")
self._physical_cores_count = cores
self._physical_processors_count = processors