run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
[ original upstream message ]
--- a/tests/run-tests.py Sat Jun 18 16:52:51 2011 -0500
+++ b/tests/run-tests.py Thu Jun 30 16:25:05 2011 +0200
@@ -78,10 +78,7 @@
time.sleep(1)
p.timeout = True
if p.returncode is None:
- try:
- p.terminate()
- except OSError:
- pass
+ terminate(p)
threading.Thread(target=t).start()
return p
@@ -343,6 +340,17 @@
else:
print "WARNING: Did not find prerequisite tool: "+p
+def terminate(proc):
+ """Terminate subprocess (with fallback for Python versions < 2.6)"""
+ vlog('# Terminating process %d' % proc.pid)
+ try:
+ if hasattr(proc, 'terminate'):
+ proc.terminate()
+ else:
+ os.kill(proc.pid, signal.SIGTERM)
+ except OSError:
+ pass
+
def killdaemons():
# Kill off any leftover daemon processes
try:
@@ -651,10 +659,7 @@
proc = Popen4(cmd, wd, options.timeout)
def cleanup():
- try:
- proc.terminate()
- except OSError:
- pass
+ terminate(proc)
ret = proc.wait()
if ret == 0:
ret = signal.SIGTERM << 8