<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi All,<div><br></div><div><br></div><div><span></span><span class="chatzilla-decor">&gt;</span><span>the files&nbsp;<span>&nbsp;:</span></span></div><div><br></div><div><span><span></span><span><a target="_content" class="chatzilla-link" href="http://www.geofemengineering.it/data/qt_proc.py">http://www.geofemeng<wbr>ineering.it/data/<wbr>qt_proc.py<wbr></a>&nbsp;</span></span></div><div><br></div><div><span><span><a target="_content" class="chatzilla-link" href="http://www.geofemengineering.it/data/wx_proc.py">http://www.geofemeng<wbr>ineering.it/data/<wbr>wx_proc.py</a></span></span></div><div><br></div><div>are 2 examples extracted from a book,</div><div>they do the same things but the pyqt example give me :</div><div><br></div><div><br></div><div><div>Traceback (most recent call last):</div><div>&nbsp;&nbsp;File "qt_proc.py", line 102, in &lt;module&gt;</div><div>&nbsp;&nbsp; &nbsp;widget = CPUMonitor()&nbsp;</div><div>&nbsp;&nbsp;File "qt_proc.py", line 43, in __init__</div><div>&nbsp;&nbsp; &nbsp;self.timerEvent(None)</div><div>&nbsp;&nbsp;File "qt_proc.py", line 79, in timerEvent</div><div>&nbsp;&nbsp; &nbsp;result = self.get_cpu_usage()</div><div>&nbsp;&nbsp;File "qt_proc.py", line 75, in get_cpu_usage</div><div>&nbsp;&nbsp; &nbsp;return [(100.0*dt)/(total) for dt in delta]</div><div>ZeroDivisionError: float division</div><div><br></div><div><br></div><div>tring to add some prints in the code :&nbsp;</div><div><br></div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">        </span>def prepare_cpu_usage(self):&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>"""helper function to return CPU usage info"""</div><div><span class="Apple-tab-span" style="white-space:pre">                </span># get the CPU times using psutil module&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>t = p.cpu_times()</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>print 't', t</div><div><span class="Apple-tab-span" style="white-space:pre">                </span># return only the values we're interested in&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if hasattr(t, 'nice'):</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return [t.user, t.nice, t.system, t.idle]&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>else:</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span># special case for Windows, without 'nice' value</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return [t.user, 0, t.system, t.idle]&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>def get_cpu_usage(self):</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>"""Compute CPU usage comparing previous and current measurements"""</div><div><span class="Apple-tab-span" style="white-space:pre">                </span># take the current CPU usage information&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>now = self.prepare_cpu_usage()&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>print now</div><div><span class="Apple-tab-span" style="white-space:pre">                </span># compute delta between current and previous measurements</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>delta = [now[i] - self.before[i] for i in range(len(now))]&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for i in range(len(now)):</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>print now[i]</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>print self.before[i]</div><div><span class="Apple-tab-span" style="white-space:pre">                </span># compute the total (needed for percentages calculation)&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>total = sum(delta)&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>print total</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>print delta</div><div><span class="Apple-tab-span" style="white-space:pre">                </span># save the current measurement to before object&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>self.before = now</div><div><span class="Apple-tab-span" style="white-space:pre">                </span># return the percentage of CPU usage for our 4 categories&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return [(100.0*dt)/(total) for dt in delta]</div><div><br></div><div><br></div><div><br></div><div>i can see it subtract 2 identical values :</div><div><br></div><div><span class="Apple-style-span" style="font-family: LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 12px; ">t system=1e-06; idle=4294.967295; user=2.097488; nice=0.0 &nbsp; &nbsp; &nbsp; # &nbsp; &lt;- t ( print 't', t )<br style="margin-top: 0px; ">t system=1e-06; idle=4294.967295; user=2.097488; nice=0.0<br>[2.0974879999999998, 0.0, 9.9999999999999995e-07, 4294.9672950000004] &nbsp; # &nbsp;&lt;- now ( print now&nbsp;)<br>2.097488 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span class="Apple-style-span" style="font-family: LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace; font-size: 12px; ">2.097488 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #<br>0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# &nbsp; &nbsp;for i in range(len(now)):<br>0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# &nbsp; &nbsp; &nbsp; &nbsp;print now[i]<br>1e-06 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# &nbsp; &nbsp; &nbsp; &nbsp;print self.before[i]<br>1e-06 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#<br>4294.967295 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#<br>4294.967295 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#<br>0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# &nbsp; &nbsp;print total<br>[0.0, 0.0, 0.0, 0.0] &nbsp; # &nbsp; &nbsp;print delta</span></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace"><br></font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace"><br></font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace">have you any clue on what's worng ?</font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace"><br></font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace">i'm using pyqt snapshot build in&nbsp;64 bit mode on mac osx snow leopard.</font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace">sip-snapshot-4.10.1-b514b2f196b8 + PyQt-mac-gpl-snapshot-4.7.1-08c09018a2d5</font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace"><br></font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace"><br></font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace">thanks for any help!</font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace"><br></font></div><div><font class="Apple-style-span" face="LuxiMono, 'Bitstream Vera Sans Mono', Monaco, 'Courier New', monospace">Massimo.</font></div><div><br></div></div></div></body></html>