diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-02-02 22:49:30 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-02-02 22:49:30 +0100 |
commit | 1f30d13ced7faec37946b0eb7f8127b86fed4116 (patch) | |
tree | 353f35440029becdd296493964482b91efc6f27d | |
parent | 24964038e109799c890b71b0232a268fc3ed7358 (diff) | |
download | psutil-1f30d13ced7faec37946b0eb7f8127b86fed4116.tar.gz |
#966: catch IOError: [Errno 19] No such device
-rw-r--r-- | docs/index.rst | 3 | ||||
-rw-r--r-- | psutil/_pslinux.py | 10 |
2 files changed, 6 insertions, 7 deletions
diff --git a/docs/index.rst b/docs/index.rst index 0d998913..2c4c87ed 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -655,7 +655,8 @@ Sensors .. function:: sensors_battery() Return battery status information as a namedtuple including the following - values. If no battery is installed returns ``None``. + values. If no battery is installed or metrics can't be determined returns + ``None``. - **percent**: battery power left as a percentage. - **secsleft**: a rough approximation of how many seconds are left before the diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index a06ee73f..2b724fd3 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -282,14 +282,12 @@ def set_scputimes_ntuple(procfs_path): def cat(fname, fallback=_DEFAULT, binary=True): """Return file content.""" try: - f = open_binary(fname) if binary else open_text(fname) + with open_binary(fname) if binary else open_text(fname) as f: + return f.read().strip() except IOError: if fallback != _DEFAULT: return fallback raise - else: - with f: - return f.read().strip() try: @@ -1110,8 +1108,8 @@ def sensors_battery(): null = object() def multi_cat(*paths): - """Read content of multiple files which may not exist. - # If none of them exist returns None. + """Attempt to read the content of multiple files which may + not exist. If none of them exist return None. """ for path in paths: ret = cat(path, fallback=null) |