Commit a138c04a authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Complete's unix support

parent f4cf5ca9
#!/usr/bin/env python #!/usr/bin/env python
import errno
import os import os
import signal import signal
import sys import sys
import time
secs = int(sys.argv[1]) secs = int(sys.argv[1])
cmd = sys.argv[2] cmd = sys.argv[2]
def killProcess(pid):
os.killpg(pid, signal.SIGKILL)
for x in range(10):
r = os.waitpid(pid, os.WNOHANG)
if r == (0, 0):
os.killpg(pid, signal.SIGKILL)
except OSError, e:
if e.errno == errno.ECHILD:
raise e
pid = os.fork() pid = os.fork()
# XXX error checking
if pid == 0: if pid == 0:
# child # child
os.setpgrp() os.setpgrp()
...@@ -17,7 +34,7 @@ else: ...@@ -17,7 +34,7 @@ else:
# parent # parent
def handler(signum, frame): def handler(signum, frame):
sys.stderr.write('Timeout happened...killing process...\n') sys.stderr.write('Timeout happened...killing process...\n')
os.killpg(pid, signal.SIGKILL) # XXX Kill better like .hs killProcess(pid)
sys.exit(99) sys.exit(99)
old = signal.signal(signal.SIGALRM, handler) old = signal.signal(signal.SIGALRM, handler)
signal.alarm(secs) signal.alarm(secs)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment