Handle Ubuntu 12.04 psutil recursive cancel

Ubuntu has a crazy old version of psutil, we'll fall back to sigkill for
that platform
This commit is contained in:
Matthew Jones
2015-08-11 10:24:54 -04:00
parent 6c409404ba
commit 9aa89e08d9

View File

@@ -437,16 +437,20 @@ class BaseTask(Task):
if instance.cancel_flag: if instance.cancel_flag:
try: try:
if settings.AWX_PROOT_ENABLED: if settings.AWX_PROOT_ENABLED:
# NOTE: Refactor this once we get a newer psutil across the board
if not psutil: if not psutil:
os.kill(child.pid, signal.SIGKILL) os.kill(child.pid, signal.SIGKILL)
else: else:
main_proc = psutil.Process(pid=child.pid) try:
if hasattr(main_proc, "children"): main_proc = psutil.Process(pid=child.pid)
child_procs = main_proc.children(recursive=True) if hasattr(main_proc, "children"):
else: child_procs = main_proc.children(recursive=True)
child_procs = main_proc.get_children(recursive=True) else:
for child_proc in child_procs: child_procs = main_proc.get_children(recursive=True)
os.kill(child_proc.pid, signal.SIGTERM) for child_proc in child_procs:
os.kill(child_proc.pid, signal.SIGTERM)
except TypeError:
os.kill(child.pid, signal.SIGKILL)
else: else:
os.kill(child.pid, signal.SIGTERM) os.kill(child.pid, signal.SIGTERM)
time.sleep(3) time.sleep(3)