diff --git a/runner/precise_runner/runner.py b/runner/precise_runner/runner.py index a5d90635..d13c0150 100644 --- a/runner/precise_runner/runner.py +++ b/runner/precise_runner/runner.py @@ -15,6 +15,7 @@ import atexit import time +import logging from subprocess import PIPE, Popen from threading import Thread, Event @@ -172,6 +173,7 @@ def __init__(self, engine, trigger_level=3, sensitivity=0.5, stream=None, self.on_prediction = on_prediction self.on_activation = on_activation self.chunk_size = engine.chunk_size + self.logger = logging.getLogger(__name__) self.pa = None self.thread = None @@ -233,11 +235,15 @@ def _handle_predictions(self): """Continuously check Precise process output""" while self.running: chunk = self.stream.read(self.chunk_size) + self.logger.debug("stream chunk length: %s", len(chunk)) - if self.is_paused: + if self.is_paused or len(chunk) == 0: + continue + try: + prob = self.engine.get_prediction(chunk) + self.on_prediction(prob) + except Exception: + self.logger.exception("problem processing prediction: ") continue - - prob = self.engine.get_prediction(chunk) - self.on_prediction(prob) if self.detector.update(prob): self.on_activation()