<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">></span><span>the files <span> :</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> </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> File "qt_proc.py", line 102, in <module></div><div> widget = CPUMonitor() </div><div> File "qt_proc.py", line 43, in __init__</div><div> self.timerEvent(None)</div><div> File "qt_proc.py", line 79, in timerEvent</div><div> result = self.get_cpu_usage()</div><div> File "qt_proc.py", line 75, in get_cpu_usage</div><div> 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 : </div><div><br></div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">        </span>def prepare_cpu_usage(self): </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 </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 </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] </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] </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 </div><div><span class="Apple-tab-span" style="white-space:pre">                </span>now = self.prepare_cpu_usage() </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))] </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) </div><div><span class="Apple-tab-span" style="white-space:pre">                </span>total = sum(delta) </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 </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 </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 # <- 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] # <- now ( print now )<br>2.097488 # </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 #<br>0.0 # for i in range(len(now)):<br>0.0 # print now[i]<br>1e-06 # print self.before[i]<br>1e-06 #<br>4294.967295 #<br>4294.967295 #<br>0.0 # print total<br>[0.0, 0.0, 0.0, 0.0] # 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 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>