Skip to content

Commit

Permalink
Improve subprocess parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewScholefield committed Jul 18, 2020
1 parent ae0a9f9 commit fc06b6c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions runner/precise_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit fc06b6c

Please sign in to comment.