| 1 |
from __future__ import print_function |
| 2 |
import os |
| 3 |
import subprocess |
| 4 |
import sys |
| 5 |
import threading |
| 6 |
|
| 7 |
|
| 8 |
def 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. |
| 14 |
cmd = subprocess.Popen( |
| 15 |
[sys.argv[1], "--obj=" + sys.argv[2], "-f=none", "--output-style=GNU"], |
| 16 |
stdout=subprocess.PIPE, |
| 17 |
stdin=subprocess.PIPE, |
| 18 |
) |
| 19 |
watchdog = threading.Timer(20, kill_subprocess, args=[cmd]) |
| 20 |
watchdog.start() |
| 21 |
cmd.stdin.write(b"0\n") |
| 22 |
cmd.stdin.flush() |
| 23 |
print(cmd.stdout.readline()) |
| 24 |
cmd.stdin.write(b"bad\n") |
| 25 |
cmd.stdin.flush() |
| 26 |
print(cmd.stdout.readline()) |
| 27 |
watchdog.cancel() |