Correct issue on Mac OS X running in non root (issue #423)

This commit is contained in:
Nicolargo 2014-09-30 22:29:31 +02:00
parent 57569b23f3
commit d50f49eb89

View File

@ -318,7 +318,7 @@ class GlancesProcesses(object):
processdict = {}
for proc in psutil.process_iter():
# If self.get_max_processes() is None: Only retreive mandatory stats
# Else: retreive mandatoryadn standard stast
# Else: retreive mandatory and standard stats
s = self.__get_process_stats(proc,
mandatory_stats=True,
standard_stats=self.get_max_processes() is None)
@ -348,14 +348,28 @@ class GlancesProcesses(object):
except:
pass
# Process optimization
# Only retreive stats for visible processes (get_max_processes)
if self.get_max_processes() is not None:
# Sort the internal dict and cut the top N (Return a list of tuple)
# tuple=key (proc), dict (returned by __get_process_stats)
try:
processiter = sorted(processdict.items(), key=lambda x: x[1][self.getsortkey()], reverse=True)
except TypeError:
# Fallback to all process (issue #423)
processloop = processdict.items()
first = False
else:
processloop = processiter[0:self.get_max_processes()]
first = True
for i in processiter[0:self.get_max_processes()]:
else:
# Get all processes stats
processloop = processdict.items()
first = False
for i in processloop:
# Already existing mandatory stats
procstat = i[1]
if self.get_max_processes() is not None:
# Update with standard stats
# and extended stats but only for TOP (first) process
s = self.__get_process_stats(i[0],
@ -371,15 +385,6 @@ class GlancesProcesses(object):
self.processlist.append(procstat)
# Next...
first = False
else:
# Get all the processes
for i in processdict.items():
# Already existing mandatory and standard stats
procstat = i[1]
# Add a specific time_since_update stats for bitrate
procstat['time_since_update'] = time_since_update
# Update process list
self.processlist.append(procstat)
# Clean internals caches if timeout is reached
if self.cache_timer.finished():