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

Conversation

ChrisLoveringSendient
Copy link

@ChrisLoveringSendient ChrisLoveringSendient commented Nov 19, 2024

wmic is disabled by default on new versions of windows. See https://techcommunity.microsoft.com/blog/windows-itpro-blog/wmi-command-line-wmic-utility-deprecation-next-steps/4039242

Before & after:
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep  6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> cpu_info = subprocess.run(
...     "wmic CPU Get NumberOfCores /Format:csv".split(),
...     capture_output=True,
...     text=True,
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python312\Lib\subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python312\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
>>> 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])
>>> print(cpu_count_physical)
8

Copy link
Collaborator

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello!
Thanks for the PR. Is there any way to test this behavior? Are the latest version of windows on Azure not shipping wmic?

loky/backend/context.py Outdated Show resolved Hide resolved
loky/backend/context.py Show resolved Hide resolved
@ChrisLoveringSendient
Copy link
Author

Hello! Thanks for the PR. Is there any way to test this behavior? Are the latest version of windows on Azure not shipping wmic?

Thanks for the review! I am running 24H2 on my local machine, and going by the deprecation notice this the version where wmic has become disabled by default. According to the azure docs this isn't available as a hosted agent yet, which I assume this repo uses?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants