Skip to content

Commit 7756f06

Browse files
Improve subprocess parsing
1 parent e1a635e commit 7756f06

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

runner/precise_runner/runner.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,20 @@ def stop(self):
6262
def get_prediction(self, chunk):
6363
if len(chunk) != self.chunk_size:
6464
raise ValueError('Invalid chunk size: ' + str(len(chunk)))
65-
self.proc.stdin.write(chunk)
66-
self.proc.stdin.flush()
67-
return float(self.proc.stdout.readline())
65+
try:
66+
self.proc.stdin.write(chunk)
67+
self.proc.stdin.flush()
68+
line = self.proc.stdout.readline()
69+
except BrokenPipeError:
70+
raise SystemExit(0)
71+
if not line:
72+
raise SystemExit(0)
73+
else:
74+
try:
75+
return float(line)
76+
except ValueError:
77+
output = line + self.proc.stdout.read()
78+
raise RuntimeError('Engine produced the following error: {}'.format(output))
6879

6980

7081
class ListenerEngine(Engine):

0 commit comments

Comments
 (0)