Skip to content

Commit

Permalink
Crash when a process is pinned in the develop branch of Glances #2639
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Jan 6, 2024
1 parent e3f63ed commit 67b5fe1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 10 additions & 0 deletions glances/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,13 @@ def inner(self, *args, **kwargs):
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]
9 changes: 4 additions & 5 deletions glances/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -336,7 +337,7 @@ def get_extended_stats(self, proc):
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."""
Expand Down Expand Up @@ -422,7 +423,7 @@ def update(self):
# 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
###########
Expand Down Expand Up @@ -485,9 +486,7 @@ def update(self):
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
Expand Down

0 comments on commit 67b5fe1

Please sign in to comment.