diff --git a/NEWS b/NEWS index f5f00f5b..8fc5fcc0 100644 --- a/NEWS +++ b/NEWS @@ -56,6 +56,7 @@ Bugs corrected: * Fixing horizontal scrolling #1248 * Stats updated during export (thread issue) #1250 * Glances --browser crashed when more than 40 glances servers on screen 78x45 #1256 + * OSX - Python 3 and empty percent and res #1251 Backward-incompatible changes: diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index b8e63323..aa850b56 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -24,9 +24,8 @@ import shlex import copy from datetime import timedelta -from glances.compat import iteritems -from glances.globals import WINDOWS from glances.logger import logger +from glances.globals import WINDOWS from glances.processes import glances_processes, sort_stats from glances.plugins.glances_core import Plugin as CorePlugin from glances.plugins.glances_plugin import GlancesPlugin diff --git a/glances/processes.py b/glances/processes.py index 1be8f9ec..f4a7d01b 100644 --- a/glances/processes.py +++ b/glances/processes.py @@ -253,6 +253,11 @@ class GlancesProcesses(object): # User filter not (self._filter.is_filtered(p.info))] + # !!! TODO: Remove + self.processlist[0]['cpu_percent'] = None + # !!! /TODO + + # Sort the processes list by the current sort_key self.processlist = sort_stats(self.processlist, sortedby=self.sort_key, @@ -339,11 +344,11 @@ class GlancesProcesses(object): # Append the IO tag (for display) proc['io_counters'] += [io_tag] - # Compute the maximum value for keys in self._max_values_list (CPU, MEM) + # Compute the maximum value for keys in self._max_values_list: CPU, MEM for k in self._max_values_list: - if self.processlist != []: - self.set_max_values(k, max(i[k] for i in self.processlist - if not (i[k] == None))) + values_list = [i[k] for i in self.processlist if i[k] is not None] + if values_list != []: + self.set_max_values(k, max(values_list)) def getcount(self): """Get the number of processes.""" @@ -364,11 +369,16 @@ class GlancesProcesses(object): self._sort_key = key -# TODO: move this global function (also used in glances_processlist -# and logs) inside the GlancesProcesses class +def weighted(value): + """Manage None value in dict value.""" + return -float('inf') if value is None else value + + def sort_stats(stats, sortedby=None, reverse=True): - """Return the stats (dict) sorted by (sortedby) - Reverse the sort if reverse is True.""" + """Return the stats (dict) sorted by (sortedby). + + Reverse the sort if reverse is True. + """ if sortedby is None: # No need to sort... return stats @@ -383,12 +393,12 @@ def sort_stats(stats, sortedby=None, reverse=True): process[sortedby][3], reverse=reverse) except Exception: - stats.sort(key=operator.itemgetter('cpu_percent'), + stats.sort(key=lambda x: weighted(x['cpu_percent']), reverse=reverse) else: # Others sorts try: - stats.sort(key=operator.itemgetter(sortedby), + stats.sort(key=lambda x: weighted(x[sortedby]), reverse=reverse) except (KeyError, TypeError): stats.sort(key=operator.itemgetter('name'),