diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -78,10 +78,7 @@ def Popen4(cmd, wd, timeout): 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 @@ def checktools(): 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 @@ def run(cmd, wd, options, replacements): 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