From 415757535e28fe31e0b5687b8ee1ee9a491b1393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Wed, 27 Jan 2021 12:04:14 +0100 Subject: [PATCH] Catch timeout errors --- runall.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/runall.py b/runall.py index b0d8b26..2341408 100644 --- a/runall.py +++ b/runall.py @@ -5,20 +5,23 @@ chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'( def check_pair(script, instr, outstr): - result = subprocess.run( - [ - "/usr/bin/env", "bash", "-c", - ";\n".join(( - # Cleanup child processes on exit - "trap 'kill -9 $(jobs -p)' SIGINT SIGTERM EXIT", - script, - )) - ], - timeout=5, - input=instr.encode(), - capture_output=True, - ) - return result.returncode == 0 and result.stdout == outstr.encode() + try: + result = subprocess.run( + [ + "/usr/bin/env", "bash", "-c", + ";\n".join(( + # Cleanup child processes on exit + "trap 'kill -9 $(jobs -p)' SIGINT SIGTERM EXIT", + script, + )) + ], + timeout=5, + input=instr.encode(), + capture_output=True, + ) + return result.returncode == 0 and result.stdout == outstr.encode() + except subprocess.TimeoutExpired: + return False def check_pairs(script, pairs): @@ -60,9 +63,9 @@ if __name__ == '__main__': ), max_length=3) # Successor - print("\nSearching for successor") - find_script(( - ("1", "2"), - ("2", "3"), - ("3", "4"), - ), max_length=5) + # print("\nSearching for successor") + # find_script(( + # ("1", "2"), + # ("2", "3"), + # ("3", "4"), + # ), max_length=5)