summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessio Sergi <al3hex@gmail.com>2017-01-19 17:42:19 +0100
committerAlessio Sergi <al3hex@gmail.com>2017-01-19 18:53:04 +0100
commit8885313865b7dd89b2f89324fca962033e1ef1d9 (patch)
treeadf1615e82d7b109a8b84a4986bab1b60391a878
parent47a85eec5ef5b19399bcc218c1d3ab57d2ee1038 (diff)
Except AttributeError when checking for 'io_counters'
That's way better than checking for the OS; psutil may implement it for new platforms in the future.
-rw-r--r--glances/processes.py49
1 files changed, 23 insertions, 26 deletions
diff --git a/glances/processes.py b/glances/processes.py
index 3bc9cd7e..0ab68b85 100644
--- a/glances/processes.py
+++ b/glances/processes.py
@@ -21,7 +21,7 @@ import operator
import os
from glances.compat import iteritems, itervalues, listitems
-from glances.globals import BSD, LINUX, MACOS, SUNOS, WINDOWS
+from glances.globals import BSD, LINUX, MACOS, WINDOWS
from glances.timer import Timer, getTimeSinceLastUpdate
from glances.processes_tree import ProcessTreeNode
from glances.filter import GlancesFilter
@@ -279,32 +279,29 @@ class GlancesProcesses(object):
# If io_tag = 0 > Access denied (display "?")
# If io_tag = 1 > No access denied (display the IO rate)
# Availability: all platforms except macOS and Illumos/Solaris
- if not (MACOS or SUNOS):
+ try:
+ # Get the process IO counters
+ proc_io = proc.io_counters()
+ io_new = [proc_io.read_bytes, proc_io.write_bytes]
+ except (psutil.AccessDenied, psutil.NoSuchProcess, NotImplementedError, AttributeError):
+ # Access denied to process IO (no root account)
+ # NoSuchProcess (process die between first and second grab)
+ # Put 0 in all values (for sort) and io_tag = 0 (for display)
+ procstat['io_counters'] = [0, 0] + [0, 0]
+ io_tag = 0
+ else:
+ # For IO rate computation
+ # Append saved IO r/w bytes
try:
- # Get the process IO counters
- proc_io = proc.io_counters()
- io_new = [proc_io.read_bytes, proc_io.write_bytes]
- except (psutil.AccessDenied, psutil.NoSuchProcess, NotImplementedError):
- # Access denied to process IO (no root account)
- # NoSuchProcess (process die between first and second grab)
- # Put 0 in all values (for sort) and io_tag = 0 (for
- # display)
- procstat['io_counters'] = [0, 0] + [0, 0]
- io_tag = 0
- else:
- # For IO rate computation
- # Append saved IO r/w bytes
- try:
- procstat['io_counters'] = io_new + \
- self.io_old[procstat['pid']]
- except KeyError:
- procstat['io_counters'] = io_new + [0, 0]
- # then save the IO r/w bytes
- self.io_old[procstat['pid']] = io_new
- io_tag = 1
-
- # Append the IO tag (for display)
- procstat['io_counters'] += [io_tag]
+ procstat['io_counters'] = io_new + self.io_old[procstat['pid']]
+ except KeyError:
+ procstat['io_counters'] = io_new + [0, 0]
+ # then save the IO r/w bytes
+ self.io_old[procstat['pid']] = io_new
+ io_tag = 1
+
+ # Append the IO tag (for display)
+ procstat['io_counters'] += [io_tag]
return procstat