[lit] Fix handling of per test timeout when the installed psutil version
authorDan Liew <dan@su-root.co.uk>
Wed, 13 Jan 2016 16:43:49 +0000 (16:43 +0000)
committerDan Liew <dan@su-root.co.uk>
Wed, 13 Jan 2016 16:43:49 +0000 (16:43 +0000)
is < ``2.0``.

Older versions of psutil (e.g. ``1.2.1`` which is the version shipped with
Ubuntu 14.04) use a different API for retrieving the child processes.
To handle this try the new API first and if that fails try the old API.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257616 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/util.py

index a6e8d52c075491bd41a04f5c2a62d365c1643f74..40a577168692492456b0d5a22a7cfbe72acec812 100644 (file)
@@ -267,7 +267,14 @@ def killProcessAndChildren(pid):
     import psutil
     try:
         psutilProc = psutil.Process(pid)
-        for child in psutilProc.children(recursive=True):
+        # Handle the different psutil API versions
+        try:
+            # psutil >= 2.x
+            children_iterator = psutilProc.children(recursive=True)
+        except AttributeError:
+            # psutil 1.x
+            children_iterator = psutilProc.get_children(recursive=True)
+        for child in children_iterator:
             try:
                 child.kill()
             except psutil.NoSuchProcess: