summaryrefslogtreecommitdiff
path: root/psutil/_pssunos.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-08-06 00:08:34 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-08-06 00:08:34 +0200
commitc01e00533389a4f3ad285caf65afe2e53c9c063f (patch)
tree7330d0b427b1ccff7d9d88dd9e4bd99bc4a424a1 /psutil/_pssunos.py
parent23591b5adc9862db9af937532fc8cb31494f3015 (diff)
downloadpsutil-c01e00533389a4f3ad285caf65afe2e53c9c063f.tar.gz
fix #857: [SunOS] Process.cpu_times() may raise RuntimeError if attempting to query a 64bit process with a 32bit python. 0.0 times are returned as a fallback
Diffstat (limited to 'psutil/_pssunos.py')
-rw-r--r--psutil/_pssunos.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py
index 11ea4efe..382087aa 100644
--- a/psutil/_pssunos.py
+++ b/psutil/_pssunos.py
@@ -426,7 +426,21 @@ class Process(object):
@wrap_exceptions
def cpu_times(self):
- times = cext.proc_cpu_times(self.pid, self._procfs_path)
+ try:
+ times = cext.proc_cpu_times(self.pid, self._procfs_path)
+ except OSError as err:
+ is_64bit = sys.maxsize > 2**32
+ if err.errno == errno.EOVERFLOW and not is_64bit:
+ # We may get here if we attempt to query a 64bit process
+ # with a 32bit python.
+ # Error originates from read() and also tools like "cat"
+ # fail in the same way (!).
+ # Since there simply is no way to determine CPU times we
+ # return 0.0 as a fallback. See:
+ # https://github.com/giampaolo/psutil/issues/857
+ times = (0.0, 0.0, 0.0, 0.0)
+ else:
+ raise
return _common.pcputimes(*times)
@wrap_exceptions