Updated Python batch tester program to handle the failure of launching workers more gracefully.

pull/16/head
Project Nayuki 7 years ago
parent 03b502946d
commit abac3dd071

@ -25,7 +25,7 @@
# #
from __future__ import print_function from __future__ import print_function
import itertools, random, subprocess, sys import itertools, random, subprocess, sys, time
if sys.version_info.major < 3: if sys.version_info.major < 3:
raise RuntimeError("Requires Python 3+") raise RuntimeError("Requires Python 3+")
@ -39,9 +39,29 @@ CHILD_PROGRAMS = [
] ]
subprocs = []
def main(): def main():
# Launch workers
global subprocs global subprocs
subprocs = [subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True) for args in CHILD_PROGRAMS] try:
for args in CHILD_PROGRAMS:
subprocs.append(subprocess.Popen(args, universal_newlines=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE))
except FileNotFoundError:
write_all(-1)
raise
# Check if any died
time.sleep(0.3)
if any(proc.poll() is not None for proc in subprocs):
for proc in subprocs:
if proc.poll() is None:
print(-1, file=proc.stdin)
proc.stdin.flush()
sys.exit("Error: One or more workers failed to start")
# Do tests
for i in itertools.count(): for i in itertools.count():
print("Trial {}: ".format(i), end="") print("Trial {}: ".format(i), end="")
do_trial() do_trial()

Loading…
Cancel
Save