From 7756f061622fecd7c65b35a5ff9f08c56897b1c2 Mon Sep 17 00:00:00 2001 From: "Matthew D. Scholefield" Date: Sat, 18 Jul 2020 03:02:58 -0500 Subject: [PATCH] Improve subprocess parsing --- runner/precise_runner/runner.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/runner/precise_runner/runner.py b/runner/precise_runner/runner.py index a5d90635..c403616b 100644 --- a/runner/precise_runner/runner.py +++ b/runner/precise_runner/runner.py @@ -62,9 +62,20 @@ def stop(self): def get_prediction(self, chunk): if len(chunk) != self.chunk_size: raise ValueError('Invalid chunk size: ' + str(len(chunk))) - self.proc.stdin.write(chunk) - self.proc.stdin.flush() - return float(self.proc.stdout.readline()) + try: + self.proc.stdin.write(chunk) + self.proc.stdin.flush() + line = self.proc.stdout.readline() + except BrokenPipeError: + raise SystemExit(0) + if not line: + raise SystemExit(0) + else: + try: + return float(line) + except ValueError: + output = line + self.proc.stdout.read() + raise RuntimeError('Engine produced the following error: {}'.format(output)) class ListenerEngine(Engine):