Compare commits

..

No commits in common. "cd6197caa33e9356e97518eaf54a5cfa592670da" and "415757535e28fe31e0b5687b8ee1ee9a491b1393" have entirely different histories.

1 changed files with 18 additions and 23 deletions

View File

@ -1,31 +1,26 @@
from itertools import product from itertools import product
import signal import subprocess
from subprocess import DEVNULL, PIPE, Popen, TimeoutExpired
chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ' chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ '
# Prevent zombie processes
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
def check_pair(script, instr, outstr): def check_pair(script, instr, outstr):
process = Popen(
["/usr/bin/env", "bash", "-c", "--", script],
stdin=PIPE,
stdout=PIPE,
stderr=DEVNULL,
)
try: try:
stdout, stderr = process.communicate(instr.encode(), timeout=5) result = subprocess.run(
return process.returncode == 0 and stdout == outstr.encode() [
except TimeoutExpired: "/usr/bin/env", "bash", "-c",
try: ";\n".join((
process.kill() # Cleanup child processes on exit
stdout, stderr = process.communicate() "trap 'kill -9 $(jobs -p)' SIGINT SIGTERM EXIT",
except ProcessLookupError: script,
pass ))
],
timeout=5,
input=instr.encode(),
capture_output=True,
)
return result.returncode == 0 and result.stdout == outstr.encode()
except subprocess.TimeoutExpired:
return False return False
@ -63,8 +58,8 @@ if __name__ == '__main__':
print("\nSearching for identity") print("\nSearching for identity")
find_script(( find_script((
("1", "1"), ("1", "1"),
("42", "42"), ("2", "2"),
("1984", "1984"), ("3", "3"),
), max_length=3) ), max_length=3)
# Successor # Successor