Catch timeout errors

This commit is contained in:
Mattéo Delabre 2021-01-27 12:04:14 +01:00
parent c52a06c09c
commit 415757535e
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 23 additions and 20 deletions

View File

@ -5,20 +5,23 @@ chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'(
def check_pair(script, instr, outstr): def check_pair(script, instr, outstr):
result = subprocess.run( try:
[ result = subprocess.run(
"/usr/bin/env", "bash", "-c", [
";\n".join(( "/usr/bin/env", "bash", "-c",
# Cleanup child processes on exit ";\n".join((
"trap 'kill -9 $(jobs -p)' SIGINT SIGTERM EXIT", # Cleanup child processes on exit
script, "trap 'kill -9 $(jobs -p)' SIGINT SIGTERM EXIT",
)) script,
], ))
timeout=5, ],
input=instr.encode(), timeout=5,
capture_output=True, input=instr.encode(),
) capture_output=True,
return result.returncode == 0 and result.stdout == outstr.encode() )
return result.returncode == 0 and result.stdout == outstr.encode()
except subprocess.TimeoutExpired:
return False
def check_pairs(script, pairs): def check_pairs(script, pairs):
@ -60,9 +63,9 @@ if __name__ == '__main__':
), max_length=3) ), max_length=3)
# Successor # Successor
print("\nSearching for successor") # print("\nSearching for successor")
find_script(( # find_script((
("1", "2"), # ("1", "2"),
("2", "3"), # ("2", "3"),
("3", "4"), # ("3", "4"),
), max_length=5) # ), max_length=5)