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] get load avg doesn't display meaningful results even after 5 seconds #2498

Closed
Nathan22211 opened this issue Jan 13, 2025 · 3 comments

Comments

@Nathan22211
Copy link

Summary

  • OS: Windows 11 24H2, Build 26100.2605
  • Architecture: x86-64
  • Psutil version: 6.1.1
  • Python version: 3.12.8
  • Type: python virtual environment running with VScode
  • CPU: r7 5700x

Description

getloadavg() only returns a zeroed-out tuple i.e. (0.0, 0.0, 0.0) when used on windows 11. I've already narrowed it down to this part load = psutil.getloadavg()[0]

The code example below is from one of my projects utilizing psutil. if I were to have this function where CPU percent is in this code: https://github.com/FyreX-opensource-design/open-system-monitor/blob/main/app.py, the Core load would display 0.0 % on the webpage

def CPUcoreLoad():
    cpuCores = psutil.cpu_count(logical=False)
    load = psutil.getloadavg()[0]
    return load / cpuCores * 100```
@giampaolo
Copy link
Owner

From doc:

On Windows this is emulated by using a Windows API that spawns a thread which keeps running in background and updates results every 5 seconds, mimicking the UNIX behavior. Thus, on Windows, the first time this is called and for the next 5 seconds it will return a meaningless (0.0, 0.0, 0.0) tuple.

You should be able to see meaningful results if you call getloadavg() again after 5 secs.

@mgineer85
Copy link

Can confirm having the same issue as OP - I only get values when setting interval to any value different than None. But as I do not want a blocking call I cannot use it that way.

@mgineer85
Copy link

cpu_percent works as intended - loadavg is always a tuple of 3 0.0 values

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