brintos

brintos / llvm-project-archived public Read only

0
0
Text · 639 B · c8e0b95 Raw
28 lines · python
1from __future__ import print_function2import os3import subprocess4import sys5import threading6 7 8def kill_subprocess(process):9    process.kill()10    os._exit(1)11 12 13# Pass -f=none and --output-style=GNU to get only one line of output per input.14cmd = subprocess.Popen(15    [sys.argv[1], "--obj=" + sys.argv[2], "-f=none", "--output-style=GNU"],16    stdout=subprocess.PIPE,17    stdin=subprocess.PIPE,18)19watchdog = threading.Timer(20, kill_subprocess, args=[cmd])20watchdog.start()21cmd.stdin.write(b"0\n")22cmd.stdin.flush()23print(cmd.stdout.readline())24cmd.stdin.write(b"bad\n")25cmd.stdin.flush()26print(cmd.stdout.readline())27watchdog.cancel()28