summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2024-01-06 11:00:01 +0100
committernicolargo <nicolas@nicolargo.com>2024-01-06 11:00:01 +0100
commit67b5fe1a1664a9eef2cf68938df7c56245ef217f (patch)
tree7a6ad137b84d56d3ee92305d654237719c68a7ee
parente3f63ed4ce64e1e589ea501bfea03a0e6f138b04 (diff)
Crash when a process is pinned in the develop branch of Glances #2639
-rw-r--r--glances/globals.py10
-rw-r--r--glances/processes.py9
2 files changed, 14 insertions, 5 deletions
diff --git a/glances/globals.py b/glances/globals.py
index e4e42ec8..a88af241 100644
--- a/glances/globals.py
+++ b/glances/globals.py
@@ -426,3 +426,13 @@ def weak_lru_cache(maxsize=128, typed=False):
return inner
return wrapper
+
+
+def namedtuple_to_dict(data):
+ """Convert a namedtuple to a dict, using the _asdict() method embeded in PsUtil stats."""
+ return {k: (v._asdict() if hasattr(v, '_asdict') else v) for k, v in data.items()}
+
+
+def list_of_namedtuple_to_list_of_dict(data):
+ """Convert a list of namedtuples to a dict, using the _asdict() method embeded in PsUtil stats."""
+ return [namedtuple_to_dict(d) for d in data]
diff --git a/glances/processes.py b/glances/processes.py
index 74606786..7666420f 100644
--- a/glances/processes.py
+++ b/glances/processes.py
@@ -10,6 +10,7 @@
import os
from glances.globals import BSD, LINUX, MACOS, WINDOWS, iterkeys
+from glances.globals import namedtuple_to_dict, list_of_namedtuple_to_list_of_dict
from glances.timer import Timer, getTimeSinceLastUpdate
from glances.filter import GlancesFilter
from glances.programs import processes_to_programs
@@ -336,7 +337,7 @@ class GlancesProcesses(object):
ret[stat_prefix + '_mean'] = ret[stat_prefix + '_mean_sum'] / ret[stat_prefix + '_mean_counter']
ret['extended_stats'] = True
- return ret
+ return namedtuple_to_dict(ret)
def is_selected_extended_process(self, position):
"""Return True if the process is the selected one for extended stats."""
@@ -422,7 +423,7 @@ class GlancesProcesses(object):
# Grab extended stats only for the selected process (see issue #2225)
if self.extended_process is not None and proc['pid'] == self.extended_process['pid']:
proc.update(self.get_extended_stats(self.extended_process))
- self.extended_process = proc
+ self.extended_process = namedtuple_to_dict(proc)
# Meta data
###########
@@ -485,9 +486,7 @@ class GlancesProcesses(object):
processlist = list(filter(lambda p: not self._filter.is_filtered(p), processlist))
# Save the new processlist and transform all namedtuples to dict
- self.processlist = [
- {k: (v._asdict() if hasattr(v, '_asdict') else v) for k, v in p.items()} for p in processlist
- ]
+ self.processlist = list_of_namedtuple_to_list_of_dict(processlist)
# Compute the maximum value for keys in self._max_values_list: CPU, MEM
# Useful to highlight the processes with maximum values