Skip to content

Commit

Permalink
fix #1323: [Linux] sensors_temperatures() may fail with ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Aug 13, 2018
1 parent 32cefd0 commit 5bd44f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ XXXX-XX-XX
statuses (returns '?').
- 1313_: [Linux] disk_io_counters() can report inflated IO counters due to
erroneously counting base disk device and its partition(s) twice.
- 1323_: [Linux] sensors_temperatures() may fail with ValueError.

5.4.6
=====
Expand Down
18 changes: 13 additions & 5 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def cat(fname, fallback=_DEFAULT, binary=True):
try:
with open_binary(fname) if binary else open_text(fname) as f:
return f.read().strip()
except IOError:
except (IOError, OSError):
if fallback is not _DEFAULT:
return fallback
else:
Expand Down Expand Up @@ -1199,13 +1199,15 @@ def sensors_temperatures():
current = float(cat(path)) / 1000.0
path = os.path.join(os.path.dirname(base), 'name')
unit_name = cat(path, binary=False)
except (IOError, OSError) as err:
except (IOError, OSError, ValueError) as err:
# A lot of things can go wrong here, so let's just skip the
# whole entry.
# whole entry. Sure thing is Linux's /sys/class/hwmon really
# is a stinky broken mess.
# https://github.com/giampaolo/psutil/issues/1009
# https://github.com/giampaolo/psutil/issues/1101
# https://github.com/giampaolo/psutil/issues/1129
# https://github.com/giampaolo/psutil/issues/1245
# https://github.com/giampaolo/psutil/issues/1323
warnings.warn("ignoring %r for file %r" % (err, path),
RuntimeWarning)
continue
Expand All @@ -1215,9 +1217,15 @@ def sensors_temperatures():
label = cat(base + '_label', fallback='', binary=False)

if high is not None:
high = float(high) / 1000.0
try:
high = float(high) / 1000.0
except ValueError:
high = None
if critical is not None:
critical = float(critical) / 1000.0
try:
critical = float(critical) / 1000.0
except ValueError:
critical = None

ret[unit_name].append((label, current, high, critical))

Expand Down

0 comments on commit 5bd44f8

Please sign in to comment.