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

RaspberryCM4/Apache/Django/psutil596: cpu_percent(..) returns the correct value only once, getloadavg() too #2332

Closed
grasmax opened this issue Nov 30, 2023 · 1 comment

Comments

@grasmax
Copy link

grasmax commented Nov 30, 2023

Summary

  • OS: Raspberry Pi Compute Module 4 Rev 1.1 Mar 17 2023, Raspbian GNU/Linux 11 (bullseye)
  • Architecture: 32bit
  • Psutil version: 5.9.6
  • Python version: 3.9.2
  • Type: core
  • wsgi: daemon, MaxRequestPerChild (obsolete) not set

Description

If I call a python script like

import psutil
print(psutil.cpu_percent(interval=1, percpu=True))

a few times within in a putty session, it shows different values:
cpu from shell

If cpu_percent() is called from a apache/django/mvt python script, than it returns the correct value only once.
All further calls always return the same value.
I need to restart the Apache service to get new values.

@grasmax grasmax added the bug label Nov 30, 2023
@github-actions github-actions bot added the linux label Nov 30, 2023
@grasmax grasmax changed the title RaspberryCM4/Apache/Django/psutil596: Result of cpu_percent(..) is 0 RaspberryCM4/Apache/Django/psutil596: cpu_percent(..) returns the correct value only once Nov 30, 2023
@grasmax grasmax changed the title RaspberryCM4/Apache/Django/psutil596: cpu_percent(..) returns the correct value only once RaspberryCM4/Apache/Django/psutil596: cpu_percent(..) returns the correct value only once, getloadavg() too Dec 4, 2023
@grasmax grasmax closed this as completed Dec 4, 2023
@grasmax
Copy link
Author

grasmax commented Dec 4, 2023

Problem: cpu_percent() and getloadavg() were called in a construktor of a model class and stored to a static member.
Solution: the result of cpu_percent() and getloadavg() are stored in a member variable of an instance of the model class.

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

1 participant