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

无法输出状态信息:RuntimeError: PdhAddEnglishCounterW failed. #50

Closed
EillesWan opened this issue Jul 14, 2024 · 1 comment
Closed
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@EillesWan
Copy link
Contributor

问题反馈

描述问题

正在环境:

处理器 AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx
内存 8 吉字节
DX DirectX 12 (FL 12.1)
版本 Windows 10 专业版19045.4651
版号 22H2 19045.4651
体验 Windows Feature Experience Pack 1000.19060.1000.0
磐蛇 Python v3.10.11:7d4cc5a [MSC v.1929 64 bit (AMD64)] on win32

下运行轻雪机器人,发现 psutil 库获取系统运行状态信息时出现以下错误:

  File ...\LiteyukiBot\src\plugins\liteyuki_status\api.py", line 226, in get_hardware_data
    swap = psutil.swap_memory()
  File "...\LiteyukiBot\.venv\lib\site-packages\psutil\__init__.py", line 2036, in swap_memory
    return _psplatform.swap_memory()
  File "...\LiteyukiBot\.venv\lib\site-packages\psutil\_pswindows.py", line 266, in swap_memory
    percentswap = cext.swap_percent()
RuntimeError: PdhAddEnglishCounterW failed. Performance counters may be disabled.

如何复现

暂无复现方案

预期

预期生成状态信息:使用 状态 命令,令轻雪机器人调取 psutil 库,获取系统状态

实际

后台控制台出现如上错误,无法输出状态信息。

@EillesWan
Copy link
Contributor Author

参考 giampaolo/psutil#2105

此问题应为未开启计数器而产生,可以如下解决:

使用命令行执行以下命令:

reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib" /v "Disable"
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib" /v "Disable" /t "REG_BINARY" /d 00
lodctr /R

或者:

  1. 打开注册表编辑器
  2. 找到键:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib
  3. 若在此目录下:
    • 存在名为 Disable 的键,将其值设置为 0
    • 不存在上述键,新建之,设置其值为 0,类型 二进制(Binary)
  4. 保存注册表信息,并打开控制台
  5. 在控制台执行命令:lodctr /R

@snowykami snowykami added bug Something isn't working good first issue Good for newcomers labels Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants