Skip to content

Commit

Permalink
Use Get-WmiObject instead of wmic for counting cores on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoveringSendient committed Nov 19, 2024
1 parent 2bfa386 commit a77d449
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions loky/backend/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,32 @@ def _count_physical_cores():
cpu_info = {line for line in cpu_info if not line.startswith("#")}
cpu_count_physical = len(cpu_info)
elif sys.platform == "win32":
cpu_info = subprocess.run(
"wmic CPU Get NumberOfCores /Format:csv".split(),
capture_output=True,
text=True,
)
cpu_info = cpu_info.stdout.splitlines()
cpu_info = [
l.split(",")[1]
for l in cpu_info
if (l and l != "Node,NumberOfCores")
]
cpu_count_physical = sum(map(int, cpu_info))
try:
cpu_info = subprocess.run(
"wmic CPU Get NumberOfCores /Format:csv".split(),
capture_output=True,
text=True,
)
except FileNotFoundError:
cpu_info = subprocess.run(
(
"powershell Get-WmiObject "
"-Class 'win32_processor' -Property 'numberOfCores' | "
"Select-Object -ExpandProperty 'numberOfCores'"
).split(),
capture_output=True,
text=True,
)
cpu_info = cpu_info.stdout.splitlines()
cpu_count_physical = int(cpu_info[0])
else:
cpu_info = cpu_info.stdout.splitlines()
cpu_info = [
l.split(",")[1]
for l in cpu_info
if (l and l != "Node,NumberOfCores")
]
cpu_count_physical = sum(map(int, cpu_info))
elif sys.platform == "darwin":
cpu_info = subprocess.run(
"sysctl -n hw.physicalcpu".split(),
Expand Down

0 comments on commit a77d449

Please sign in to comment.