Skip to content

Commit

Permalink
fix #1357: do not expose Process' memory_maps() and io_counters() met…
Browse files Browse the repository at this point in the history
…hods if not supported by the kernel
  • Loading branch information
giampaolo committed Dec 10, 2018
1 parent 790292d commit 314ab75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 314ab75

Please sign in to comment.