giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.32k stars 1.39k forks source link

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

Closed grasmax closed 12 months ago

grasmax commented 1 year ago

Summary

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 commented 12 months ago

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.