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

[Windows 10 Pro 21H1] PdhAddEnglishCounterW failed #2105

Closed
Madelena opened this issue May 12, 2022 · 6 comments
Closed

[Windows 10 Pro 21H1] PdhAddEnglishCounterW failed #2105

Madelena opened this issue May 12, 2022 · 6 comments

Comments

@Madelena
Copy link

Summary

  • OS: Windows 10 Pro 21H1 (OS Build 19044.1645)
  • Architecture: 64bit
  • Psutil version: 5.9.0
  • Python version: 3.10.4
  • Type: { core, doc, performance, scripts, tests, wheels, new-api, installation } (Not sure what this means)

Description

I use Glances which uses psutil. When I tried to run it on one of my computers, it gave me this error. The error doesn't occur on other computers.

Error while initializing the docker plugin (No module named 'dateutil')
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts\glances.exe\__main__.py", line 7, in <module>
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\glances\__init__.py", line 189, in main
    start(config=core.get_config(), args=core.get_args())
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-package    mode = GlancesMode(config=config, args=args)
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\glances\standalone.py", line 80, in __init__
    self.stats.update()
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\glances\stats.py", line 221, in update
    self._plugins[p].update()
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\glances\plugins\glances_plugin.py", line 1157, in wrapper
    ret = fct(self, *args, **kw)
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\glances\plugins\glances_plugin.py", line 1174, in wrapper
    ret = fct(*args, **kw)
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\glances\plugins\glances_load.py", line 116, in update
    load = self._getloadavg()
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\glances\plugins\glances_load.py", line 97, in _getloadavg
    return psutil.getloadavg()
  File "C:\Users\Madelena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\psutil\_pswindows.py", line 347, in getloadavg
    cext.init_loadavg_counter()
RuntimeError: PdhAddEnglishCounterW failed

(I was referred here by @nicolargo through this bug: nicolargo/glances#2045 )

@dbwiddis
Copy link
Contributor

The code is attempting (and failing) to read the "\System\Processor Queue Length" performance counter. It is possible the counters on your machine are corrupt or disabled.

Use the Performance Monitor application (perfmon.exe) and see if you can add that counter from within the app.

  • If the counters are corrupt, attempt to rebuild them
  • If the counters are disabled, check the registry HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib and make sure there is no key "Disable" (or set it to 0).

@Madelena
Copy link
Author

Madelena commented May 17, 2022

Awesome! Typing lodctr /R (not /r) on elevated command prompt solved this.

@giampaolo
Copy link
Owner

Perhaps it's worth to mention lodctr /R in the error message, but then again, this solution appears to be Windows-server only:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/lodctr

@dbwiddis
Copy link
Contributor

You could just say “performance counters may be corrupt or disabled” which gives sufficient hints to search for a solution.

giampaolo added a commit that referenced this issue May 17, 2022
…fails

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
@giampaolo
Copy link
Owner

Good idea. Done.

@dbwiddis
Copy link
Contributor

Might want to include "corrupt or...". Also could you "graceful fallback" and simply not provide load counters in that case? Your counter thread will die but everything else should work.

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

No branches or pull requests

3 participants