Sprinkle on some try except

This commit is contained in:
Dan Buch 2018-10-12 08:31:00 -04:00
parent 0354e8e441
commit dc5c99aa62
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

View File

@ -61,8 +61,11 @@ def _hwtemp(conf=THINKFAN_CONF):
for line in tfc_fp.readlines():
if not line.startswith('hwmon '):
continue
with open(line.split(' ')[1].strip()) as temp_fp:
temps.append(float(temp_fp.read()))
try:
with open(line.split(' ')[1].strip()) as temp_fp:
temps.append(float(temp_fp.read()))
except (OSError, IOError) as exc:
sys.stderr.write(str(exc) + '\n')
avg_temp = float(sum(temps)) / len(temps) / 1000.0
color = None
@ -102,15 +105,19 @@ def main(bits=_BITS):
loaded = json.loads(line)
for idx, name, func in bits:
value, color = func()
if value is None:
continue
try:
value, color = func()
if value is None:
continue
record = dict(full_text=str(value), name=name)
if color is not None:
record.update(dict(color=color))
record = dict(full_text=str(value), name=name)
if color is not None:
record.update(dict(color=color))
loaded.insert(idx, record)
loaded.insert(idx, record)
except Exception as exc:
sys.stderr.write(str(exc) + '\n')
sys.stderr.flush()
_print_line(prefix+json.dumps(loaded))