[PATCH 1 of 2 stable] run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()

Thomas Arendsen Hein thomas at intevation.de
Thu Jun 30 09:39:18 CDT 2011


# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Date 1309443905 -7200
# Branch stable
# Node ID c7991244cf89756e74aa34c8a1178031ca8e4d4d
# Parent  7ba7459875cb139ab996412b99d4a6c9dec0041f
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()

diff -r 7ba7459875cb -r c7991244cf89 tests/run-tests.py
--- a/tests/run-tests.py	Wed Jun 29 16:05:41 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


More information about the Mercurial-devel mailing list