Skip to content

Commit 9bea066

Browse files
committed
Make score-wrap.py fail if the read thread fails
1 parent 1e3d86e commit 9bea066

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

score-wrap.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@ def stdin_to_child(out_queue, stdin, child_in):
2929
"""Reads sys.stdin and queues all lines for writing output. Lines that need
3030
to be scored are also fed to the child process. Ends with putting a None on
3131
the queue to indicate the feeding is done."""
32-
for line in stdin:
33-
parts = line.rstrip("\n").split("\t")
34-
35-
if parts[-1] == "0":
36-
pass
37-
elif parts[-1] == "1":
38-
child_in.write("\t".join(parts[:4]) + "\n")
39-
else:
40-
raise Exception(f"Unknown input in score column: '{parts[-1]}'. Only expecting '0' or '1'.")
41-
42-
out_queue.put(parts[-1])
43-
44-
out_queue.put(None)
45-
child_in.close()
32+
try:
33+
for line in stdin:
34+
parts = line.rstrip("\n").split("\t")
35+
36+
if parts[-1] == "0":
37+
pass
38+
elif parts[-1] == "1":
39+
child_in.write("\t".join(parts[:4]) + "\n")
40+
else:
41+
raise Exception(f"Unknown input in score column: '{parts[-1]}'. Only expecting '0' or '1'.")
42+
43+
out_queue.put(parts[-1])
44+
out_queue.put(None)
45+
except Exception as e:
46+
out_queue.put(e)
47+
finally:
48+
child_in.close()
4649

4750

4851
def child_to_stdout(out_queue, child_out, stdout):
@@ -56,6 +59,9 @@ def child_to_stdout(out_queue, child_out, stdout):
5659
if line is None:
5760
break
5861

62+
if isinstance(line, Exception):
63+
raise line
64+
5965
# 0 skips child, just writes 0
6066
elif line == "0":
6167
stdout.write("0\n")
@@ -101,6 +107,8 @@ def main(argv):
101107
# actual score from child. Will stop when it encounters None in queue.
102108
child_to_stdout(queue, child.stdout, sys.stdout)
103109

110+
feeder.join()
111+
104112
# Assuming we've processed all output, child should be finished producing
105113
# output by now.
106114
child.wait()

0 commit comments

Comments
 (0)