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 2 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:
cpu_info = subprocess.run(

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

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L257-L258

Added lines #L257 - L258 were not covered by tests
"wmic CPU Get NumberOfCores /Format:csv".split(),
capture_output=True,
text=True,
)
except FileNotFoundError:
cpu_info = subprocess.run(

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

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L263-L264

Added lines #L263 - L264 were not covered by tests
ChrisLoveringSendient marked this conversation as resolved.
Show resolved Hide resolved
(
"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 274 in loky/backend/context.py

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L273-L274

Added lines #L273 - L274 were not covered by tests
else:
cpu_info = cpu_info.stdout.splitlines()

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

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L276

Added line #L276 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))

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

View check run for this annotation

Codecov / codecov/patch

loky/backend/context.py#L282

Added line #L282 was not covered by tests
ChrisLoveringSendient marked this conversation as resolved.
Show resolved Hide resolved
elif sys.platform == "darwin":
cpu_info = subprocess.run(
"sysctl -n hw.physicalcpu".split(),
Expand Down
Loading