From 9aa89e08d95a5a244cdb5a9f5bc79e9e24f61517 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Tue, 11 Aug 2015 10:24:54 -0400 Subject: [PATCH] Handle Ubuntu 12.04 psutil recursive cancel Ubuntu has a crazy old version of psutil, we'll fall back to sigkill for that platform --- awx/main/tasks.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 71ef56d6b1..eabbe94a5e 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -437,16 +437,20 @@ class BaseTask(Task): if instance.cancel_flag: try: if settings.AWX_PROOT_ENABLED: + # NOTE: Refactor this once we get a newer psutil across the board if not psutil: os.kill(child.pid, signal.SIGKILL) else: - main_proc = psutil.Process(pid=child.pid) - if hasattr(main_proc, "children"): - child_procs = main_proc.children(recursive=True) - else: - child_procs = main_proc.get_children(recursive=True) - for child_proc in child_procs: - os.kill(child_proc.pid, signal.SIGTERM) + try: + main_proc = psutil.Process(pid=child.pid) + if hasattr(main_proc, "children"): + child_procs = main_proc.children(recursive=True) + else: + child_procs = main_proc.get_children(recursive=True) + for child_proc in child_procs: + os.kill(child_proc.pid, signal.SIGTERM) + except TypeError: + os.kill(child.pid, signal.SIGKILL) else: os.kill(child.pid, signal.SIGTERM) time.sleep(3)