Fallback for PsUtil 2.0

This commit is contained in:
nicolargo 2018-01-24 21:39:08 +01:00
parent fb93c96935
commit ad032497c5

View File

@ -301,6 +301,7 @@ class GlancesProcesses(object):
mandatories_attr += ['io_counters']
# and build the processes stats list
try:
self.processlist = [p.info for p in psutil.process_iter(attrs=mandatories_attr,
ad_value=None)
# OS specifics processes filter
@ -310,8 +311,19 @@ class GlancesProcesses(object):
# Kernel threads filter
not (self.no_kernel_threads and LINUX and p.info['gids'].real == 0) and
# User filter
not (self._filter.is_filtered(p.info))
]
not (self._filter.is_filtered(p.info))]
except TypeError:
# Fallback for PsUtil 2.0
before_filter = [p.as_dict(attrs=mandatories_attr, ad_value=None) for p in psutil.process_iter()]
self.processlist = [p for p in before_filter
# OS specifics processes filter
if not (BSD and p['name'] == 'idle') and
not (WINDOWS and p['name'] == 'System Idle Process') and
not (MACOS and p['name'] == 'kernel_task') and
# Kernel threads filter
not (self.no_kernel_threads and LINUX and p['gids'].real == 0) and
# User filter
not (self._filter.is_filtered(p))]
# Sort the processes list by the current sort_key
self.processlist = sorted(self.processlist,