Mercurial > hg
changeset 14821:2017495bd552 stable
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Thu, 30 Jun 2011 16:25:05 +0200 |
parents | 7ef125fa9b35 |
children | 760d2dae4839 |
files | tests/run-tests.py |
diffstat | 1 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/run-tests.py Thu Jun 30 13:22:12 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