diff --git a/birbnetes_iot_platform_raspberry/record_stuff.py b/birbnetes_iot_platform_raspberry/record_stuff.py index 74262e2..58aa5ef 100644 --- a/birbnetes_iot_platform_raspberry/record_stuff.py +++ b/birbnetes_iot_platform_raspberry/record_stuff.py @@ -1,3 +1,4 @@ +import logging from typing import Optional, Tuple import alsaaudio import tempfile @@ -44,10 +45,24 @@ class SlicedRecorder(Thread): current_working_file_name, current_working_file = self._request_new_file() current_samples_saved = 0 + read_failures = 0 + while self._active: - length, data = self._inp.read() + try: + length, data = self._inp.read() + except alsaaudio.ALSAAudioError as e: + logging.exception(e) + + read_failures += 1 + if read_failures >= 30: + logging.error("Too many ALSA Read errors. Bailing out...") + self._active = False + return + + continue if length > 0: # will be always larger than zero (except on error) + read_failures = 0 file_size_after_append = current_samples_saved + length if file_size_after_append > self._samples_per_slice: # Appending this would cause a too big slice