Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #158 invalid chunk size #216

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions runner/precise_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import atexit

import time
import logging
from subprocess import PIPE, Popen
from threading import Thread, Event

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()