Sprinkle on some try except
This commit is contained in:
parent
0354e8e441
commit
dc5c99aa62
25
i3wrapper.py
25
i3wrapper.py
@ -61,8 +61,11 @@ def _hwtemp(conf=THINKFAN_CONF):
|
|||||||
for line in tfc_fp.readlines():
|
for line in tfc_fp.readlines():
|
||||||
if not line.startswith('hwmon '):
|
if not line.startswith('hwmon '):
|
||||||
continue
|
continue
|
||||||
with open(line.split(' ')[1].strip()) as temp_fp:
|
try:
|
||||||
temps.append(float(temp_fp.read()))
|
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
|
avg_temp = float(sum(temps)) / len(temps) / 1000.0
|
||||||
color = None
|
color = None
|
||||||
@ -102,15 +105,19 @@ def main(bits=_BITS):
|
|||||||
|
|
||||||
loaded = json.loads(line)
|
loaded = json.loads(line)
|
||||||
for idx, name, func in bits:
|
for idx, name, func in bits:
|
||||||
value, color = func()
|
try:
|
||||||
if value is None:
|
value, color = func()
|
||||||
continue
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
record = dict(full_text=str(value), name=name)
|
record = dict(full_text=str(value), name=name)
|
||||||
if color is not None:
|
if color is not None:
|
||||||
record.update(dict(color=color))
|
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))
|
_print_line(prefix+json.dumps(loaded))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user