From 314ab75295cbcdc6d8a12f89a08d702795593eca Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Mon, 10 Dec 2018 15:04:17 +0100 Subject: [PATCH] fix #1357: do not expose Process' memory_maps() and io_counters() methods if not supported by the kernel --- HISTORY.rst | 2 ++ psutil/_pslinux.py | 15 ++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 263a381f8..59bf9f678 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -14,6 +14,8 @@ XXXX-XX-XX **Bug fixes** - 1354_: [Linux] disk_io_counters() fails on Linux kernel 4.18+. +- 1357_: [Linux] Process' memory_maps() and io_counters() method are no longer + exposed if not supported by the kernel. - 1368_: [Windows] fix psutil.Process().ionice(...) mismatch. (patch by EccoTheFlintstone) - 1370_: [Windows] improper usage of CloseHandle() may lead to override the diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index b775d39ae..51cb20096 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1642,6 +1642,7 @@ def terminal(self): except KeyError: return None + # May not be available on old kernels. if os.path.exists('/proc/%s/io' % os.getpid()): @wrap_exceptions def io_counters(self): @@ -1673,10 +1674,6 @@ def io_counters(self): except KeyError as err: raise ValueError("%r field was not found in %s; found fields " "are %r" % (err[0], fname, fields)) - else: - def io_counters(self): - raise NotImplementedError("couldn't find /proc/%s/io (kernel " - "too old?)" % self.pid) @wrap_exceptions def cpu_times(self): @@ -1767,6 +1764,9 @@ def memory_maps(self): """Return process's mapped memory regions as a list of named tuples. Fields are explained in 'man proc'; here is an updated (Apr 2012) version: http://goo.gl/fmebo + + /proc/{PID}/smaps does not exist on kernels < 2.6.14 or if + CONFIG_MMU kernel configuration option is not enabled. """ def get_blocks(lines, current_block): data = {} @@ -1827,13 +1827,6 @@ def get_blocks(lines, current_block): )) return ls - else: # pragma: no cover - def memory_maps(self): - raise NotImplementedError( - "/proc/%s/smaps does not exist on kernels < 2.6.14 or " - "if CONFIG_MMU kernel configuration option is not " - "enabled." % self.pid) - @wrap_exceptions def cwd(self): try: