Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Get-WmiObject instead of wmic for counting cores on windows #423

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### 3.5.0 - in development

- Use powershell's ``Get-WmiObject`` instead of ``wmic`` for counting cores on
windows if ``wmic`` could not be found. ``wmic`` is deprecated and not available
on new builds of Windows. (#423)

### 3.4.1 - 2023-06-29

Expand Down
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 @@
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:

Check warning on line 257 in loky/backend/context.py

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L257

Added line #L257 was not covered by tests
# Wmic is not available on recent windows version
cpu_info = subprocess.run(

Check warning on line 259 in loky/backend/context.py

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L259

Added line #L259 was not covered by tests
"wmic CPU Get NumberOfCores /Format:csv".split(),
capture_output=True,
text=True,
)
cpu_info = cpu_info.stdout.splitlines()

Check warning on line 264 in loky/backend/context.py

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L264

Added line #L264 was not covered by tests
cpu_info = [
l.split(",")[1]
for l in cpu_info
if (l and l != "Node,NumberOfCores")
]
cpu_count_physical = sum(map(int, cpu_info))
except FileNotFoundError:
cpu_info = subprocess.run(

Check warning on line 272 in loky/backend/context.py

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L270-L272

Added lines #L270 - L272 were not covered by tests
(
"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])

Check warning on line 282 in loky/backend/context.py

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L281-L282

Added lines #L281 - L282 were not covered by tests
elif sys.platform == "darwin":
cpu_info = subprocess.run(
"sysctl -n hw.physicalcpu".split(),
Expand Down
Loading