I'm trying to load the cpu averages for all process id's on a host using the following snippet of code:
import psutil
while True:
for pid in psutil.pids():
p = psutil.Process(pid)
cpu_p = float(p.cpu_percent())
if cpu_p == float(100.0)
break
elif cpu_p > float(0.0):
print(cpu_p)
The problem is that the results keep returning 0.0 result. In the psutil docs, it states (ref: https://psutil.readthedocs.io/en/latest/#functions):
Warning: the first time this function is called with interval = 0.0
or None it will return a meaningless 0.0 value which you are supposed
to ignore.
How do I create a proper return value for seeking cpu_percentage in a loop instead of constantly returning a 0.0?