summaryrefslogtreecommitdiff
path: root/testsuite/timeout
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2009-10-25 15:18:21 +0000
committerIan Lynagh <igloo@earth.li>2009-10-25 15:18:21 +0000
commita138c04af52f642c30ad40fa4585ef6ed4183d82 (patch)
treecb732f80e9b33b065f4c946f4f6708bdb282fd00 /testsuite/timeout
parentf4cf5ca96742582e1f33d5da1c51b7f078c453ec (diff)
downloadhaskell-a138c04af52f642c30ad40fa4585ef6ed4183d82.tar.gz
Complete timeout.py's unix support
Diffstat (limited to 'testsuite/timeout')
-rw-r--r--testsuite/timeout/timeout.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/testsuite/timeout/timeout.py b/testsuite/timeout/timeout.py
index 66933817b3..76660a7390 100644
--- a/testsuite/timeout/timeout.py
+++ b/testsuite/timeout/timeout.py
@@ -1,14 +1,31 @@
#!/usr/bin/env python
+import errno
import os
import signal
import sys
+import time
secs = int(sys.argv[1])
cmd = sys.argv[2]
+def killProcess(pid):
+ os.killpg(pid, signal.SIGKILL)
+ for x in range(10):
+ try:
+ time.sleep(0.3)
+ r = os.waitpid(pid, os.WNOHANG)
+ if r == (0, 0):
+ os.killpg(pid, signal.SIGKILL)
+ else:
+ return
+ except OSError, e:
+ if e.errno == errno.ECHILD:
+ return
+ else:
+ raise e
+
pid = os.fork()
-# XXX error checking
if pid == 0:
# child
os.setpgrp()
@@ -17,7 +34,7 @@ else:
# parent
def handler(signum, frame):
sys.stderr.write('Timeout happened...killing process...\n')
- os.killpg(pid, signal.SIGKILL) # XXX Kill better like .hs
+ killProcess(pid)
sys.exit(99)
old = signal.signal(signal.SIGALRM, handler)
signal.alarm(secs)