giampaolo / psutil

Cross-platform lib for process and system monitoring in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

grasmax opened this issue · comments

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.

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.