[PyQt] pyqt snapshot problem to read cpu data
Massimo Di Stefano
massimodisasha at yahoo.it
Tue Feb 9 22:39:20 GMT 2010
Hi All,
>the files :
http://www.geofemengineering.it/data/qt_proc.py
http://www.geofemengineering.it/data/wx_proc.py
are 2 examples extracted from a book,
they do the same things but the pyqt example give me :
Traceback (most recent call last):
File "qt_proc.py", line 102, in <module>
widget = CPUMonitor()
File "qt_proc.py", line 43, in __init__
self.timerEvent(None)
File "qt_proc.py", line 79, in timerEvent
result = self.get_cpu_usage()
File "qt_proc.py", line 75, in get_cpu_usage
return [(100.0*dt)/(total) for dt in delta]
ZeroDivisionError: float division
tring to add some prints in the code :
def prepare_cpu_usage(self):
"""helper function to return CPU usage info"""
# get the CPU times using psutil module
t = p.cpu_times()
print 't', t
# return only the values we're interested in
if hasattr(t, 'nice'):
return [t.user, t.nice, t.system, t.idle]
else:
# special case for Windows, without 'nice' value
return [t.user, 0, t.system, t.idle]
def get_cpu_usage(self):
"""Compute CPU usage comparing previous and current measurements"""
# take the current CPU usage information
now = self.prepare_cpu_usage()
print now
# compute delta between current and previous measurements
delta = [now[i] - self.before[i] for i in range(len(now))]
for i in range(len(now)):
print now[i]
print self.before[i]
# compute the total (needed for percentages calculation)
total = sum(delta)
print total
print delta
# save the current measurement to before object
self.before = now
# return the percentage of CPU usage for our 4 categories
return [(100.0*dt)/(total) for dt in delta]
i can see it subtract 2 identical values :
t system=1e-06; idle=4294.967295; user=2.097488; nice=0.0 # <- t ( print 't', t )
t system=1e-06; idle=4294.967295; user=2.097488; nice=0.0
[2.0974879999999998, 0.0, 9.9999999999999995e-07, 4294.9672950000004] # <- now ( print now )
2.097488 #
2.097488 #
0.0 # for i in range(len(now)):
0.0 # print now[i]
1e-06 # print self.before[i]
1e-06 #
4294.967295 #
4294.967295 #
0.0 # print total
[0.0, 0.0, 0.0, 0.0] # print delta
have you any clue on what's worng ?
i'm using pyqt snapshot build in 64 bit mode on mac osx snow leopard.
sip-snapshot-4.10.1-b514b2f196b8 + PyQt-mac-gpl-snapshot-4.7.1-08c09018a2d5
thanks for any help!
Massimo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100209/735cfa1f/attachment.html>
More information about the PyQt
mailing list