Fix bug in the mic-level meter
The mic-level meter that appears in the Mycroft CLI could stop updating in
rare cases when a file I/O operation failed.  It would also fail to show
a meter ever if the mic_level file hadn't been created before the CLI was
started.
@@ -290,32 +290,30 @@ class MicMonitorThread(Thread):
def __init__(self, filename):
Thread.__init__(self)
self.filename = filename
- self.st_results = os.stat(filename)
+ self.st_results = None
def run(self):
while True:
try:
st_results = os.stat(self.filename)
- if (not st_results.st_ctime == self.st_results.st_ctime or
+ if (not self.st_results or
+ not st_results.st_ctime == self.st_results.st_ctime or
not st_results.st_mtime == self.st_results.st_mtime):
- self.read_file_from(0)
+ self.read_mic_level()
self.st_results = st_results
set_screen_dirty()
- finally:
+ except Exception:
+ # Ignore whatever failure happened and just try again later
+ pass
time.sleep(0.2)
- def read_file_from(self, bytefrom):
+ def read_mic_level(self):
global meter_cur
global meter_thresh
with io.open(self.filename, 'r') as fh:
- fh.seek(bytefrom)
- while True:
line = fh.readline()
- if line == "":
- break
-
# Just adjust meter settings
# Ex:Energy: cur=4 thresh=1.5
parts = line.split("=")
