diff --git a/awx/main/tasks.py b/awx/main/tasks.py index d3ca5280de..453038c8fc 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -23,7 +23,10 @@ import uuid from distutils.version import LooseVersion as Version import dateutil.parser import yaml -import psutil +try: + import psutil +except: + psutil = None # Pexpect import pexpect @@ -434,13 +437,16 @@ class BaseTask(Task): if instance.cancel_flag: try: if settings.AWX_PROOT_ENABLED: - main_proc = psutil.Process(pid=child.pid) - if hasattr(main_proc, "children"): - child_procs = main_proc.children(recursive=False) + if not psutil: + os.kill(child.pid, signal.SIGKILL) else: - child_procs = main_proc.get_children(recursive=False) - for child_proc in child_procs: - os.kill(child_proc.pid, signal.SIGTERM) + main_proc = psutil.Process(pid=child.pid) + if hasattr(main_proc, "children"): + child_procs = main_proc.children(recursive=False) + else: + child_procs = main_proc.get_children(recursive=False) + for child_proc in child_procs: + os.kill(child_proc.pid, signal.SIGTERM) else: os.kill(child.pid, signal.SIGTERM) time.sleep(3)