Cpu gadget: add compatibility with older psutil

not tested yet, will try tomorrow..but should work
This commit is contained in:
Davide Andreoli 2015-09-13 16:47:56 +02:00
parent 7cdd484427
commit 4386c386e4
1 changed files with 10 additions and 4 deletions

View File

@ -106,10 +106,16 @@ class Gadget(e.Gadget):
def popups_poller_cb(self):
# build an orderd list of all running procs (pid, name, cpu_perc, mun_t)
self.top_procs = [ (p.pid, p.name(),
p.cpu_percent(interval=0) / self.num_cores,
p.num_threads())
for p in psutil.process_iter() ]
if psutil.version_info[0] < 2:
self.top_procs = [ (p.pid, p.name,
p.get_cpu_percent(interval=0) / self.num_cores,
p.get_num_threads())
for p in psutil.process_iter() ]
else:
self.top_procs = [ (p.pid, p.name(),
p.cpu_percent(interval=0) / self.num_cores,
p.num_threads())
for p in psutil.process_iter() ]
self.top_procs.sort(key=itemgetter(2), reverse=True)
# update all the visible genlists