Compare commits
2 Commits
415757535e
...
cd6197caa3
Author | SHA1 | Date |
---|---|---|
Mattéo Delabre | cd6197caa3 | |
Mattéo Delabre | 30de38aa1e |
41
runall.py
41
runall.py
|
@ -1,26 +1,31 @@
|
||||||
from itertools import product
|
from itertools import product
|
||||||
import subprocess
|
import signal
|
||||||
|
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):
|
||||||
try:
|
process = Popen(
|
||||||
result = subprocess.run(
|
["/usr/bin/env", "bash", "-c", "--", script],
|
||||||
[
|
stdin=PIPE,
|
||||||
"/usr/bin/env", "bash", "-c",
|
stdout=PIPE,
|
||||||
";\n".join((
|
stderr=DEVNULL,
|
||||||
# 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:
|
try:
|
||||||
|
stdout, stderr = process.communicate(instr.encode(), timeout=5)
|
||||||
|
return process.returncode == 0 and stdout == outstr.encode()
|
||||||
|
except TimeoutExpired:
|
||||||
|
try:
|
||||||
|
process.kill()
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
except ProcessLookupError:
|
||||||
|
pass
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,8 +63,8 @@ if __name__ == '__main__':
|
||||||
print("\nSearching for identity")
|
print("\nSearching for identity")
|
||||||
find_script((
|
find_script((
|
||||||
("1", "1"),
|
("1", "1"),
|
||||||
("2", "2"),
|
("42", "42"),
|
||||||
("3", "3"),
|
("1984", "1984"),
|
||||||
), max_length=3)
|
), max_length=3)
|
||||||
|
|
||||||
# Successor
|
# Successor
|
||||||
|
|
Loading…
Reference in New Issue