提交 462f8c0b 编写于 作者: N nicolargo

OSX - Python 3 and empty percent and res #1251 - To be tested

上级 27c8c829
...@@ -56,6 +56,7 @@ Bugs corrected: ...@@ -56,6 +56,7 @@ Bugs corrected:
* Fixing horizontal scrolling #1248 * Fixing horizontal scrolling #1248
* Stats updated during export (thread issue) #1250 * Stats updated during export (thread issue) #1250
* Glances --browser crashed when more than 40 glances servers on screen 78x45 #1256 * 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: Backward-incompatible changes:
......
...@@ -24,9 +24,8 @@ import shlex ...@@ -24,9 +24,8 @@ import shlex
import copy import copy
from datetime import timedelta from datetime import timedelta
from glances.compat import iteritems
from glances.globals import WINDOWS
from glances.logger import logger from glances.logger import logger
from glances.globals import WINDOWS
from glances.processes import glances_processes, sort_stats from glances.processes import glances_processes, sort_stats
from glances.plugins.glances_core import Plugin as CorePlugin from glances.plugins.glances_core import Plugin as CorePlugin
from glances.plugins.glances_plugin import GlancesPlugin from glances.plugins.glances_plugin import GlancesPlugin
......
...@@ -253,6 +253,11 @@ class GlancesProcesses(object): ...@@ -253,6 +253,11 @@ class GlancesProcesses(object):
# User filter # User filter
not (self._filter.is_filtered(p.info))] 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 # Sort the processes list by the current sort_key
self.processlist = sort_stats(self.processlist, self.processlist = sort_stats(self.processlist,
sortedby=self.sort_key, sortedby=self.sort_key,
...@@ -339,11 +344,11 @@ class GlancesProcesses(object): ...@@ -339,11 +344,11 @@ class GlancesProcesses(object):
# Append the IO tag (for display) # Append the IO tag (for display)
proc['io_counters'] += [io_tag] 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: for k in self._max_values_list:
if self.processlist != []: values_list = [i[k] for i in self.processlist if i[k] is not None]
self.set_max_values(k, max(i[k] for i in self.processlist if values_list != []:
if not (i[k] == None))) self.set_max_values(k, max(values_list))
def getcount(self): def getcount(self):
"""Get the number of processes.""" """Get the number of processes."""
...@@ -364,11 +369,16 @@ class GlancesProcesses(object): ...@@ -364,11 +369,16 @@ class GlancesProcesses(object):
self._sort_key = key self._sort_key = key
# TODO: move this global function (also used in glances_processlist def weighted(value):
# and logs) inside the GlancesProcesses class """Manage None value in dict value."""
return -float('inf') if value is None else value
def sort_stats(stats, sortedby=None, reverse=True): def sort_stats(stats, sortedby=None, reverse=True):
"""Return the stats (dict) sorted by (sortedby) """Return the stats (dict) sorted by (sortedby).
Reverse the sort if reverse is True."""
Reverse the sort if reverse is True.
"""
if sortedby is None: if sortedby is None:
# No need to sort... # No need to sort...
return stats return stats
...@@ -383,12 +393,12 @@ def sort_stats(stats, sortedby=None, reverse=True): ...@@ -383,12 +393,12 @@ def sort_stats(stats, sortedby=None, reverse=True):
process[sortedby][3], process[sortedby][3],
reverse=reverse) reverse=reverse)
except Exception: except Exception:
stats.sort(key=operator.itemgetter('cpu_percent'), stats.sort(key=lambda x: weighted(x['cpu_percent']),
reverse=reverse) reverse=reverse)
else: else:
# Others sorts # Others sorts
try: try:
stats.sort(key=operator.itemgetter(sortedby), stats.sort(key=lambda x: weighted(x[sortedby]),
reverse=reverse) reverse=reverse)
except (KeyError, TypeError): except (KeyError, TypeError):
stats.sort(key=operator.itemgetter('name'), stats.sort(key=operator.itemgetter('name'),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册