1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

Fix psutil usage on el6 for job cancel

psutil will fail to import on el6 due to not being able to access a
pseudo terminal.  This issues a SIGKILL to the proot process in order to
force the stop
This commit is contained in:
Matthew Jones 2015-08-05 11:20:48 -04:00
parent 14df41b47b
commit efcff9b5f7

View File

@ -23,7 +23,10 @@ import uuid
from distutils.version import LooseVersion as Version from distutils.version import LooseVersion as Version
import dateutil.parser import dateutil.parser
import yaml import yaml
import psutil try:
import psutil
except:
psutil = None
# Pexpect # Pexpect
import pexpect import pexpect
@ -434,13 +437,16 @@ class BaseTask(Task):
if instance.cancel_flag: if instance.cancel_flag:
try: try:
if settings.AWX_PROOT_ENABLED: if settings.AWX_PROOT_ENABLED:
main_proc = psutil.Process(pid=child.pid) if not psutil:
if hasattr(main_proc, "children"): os.kill(child.pid, signal.SIGKILL)
child_procs = main_proc.children(recursive=False)
else: else:
child_procs = main_proc.get_children(recursive=False) main_proc = psutil.Process(pid=child.pid)
for child_proc in child_procs: if hasattr(main_proc, "children"):
os.kill(child_proc.pid, signal.SIGTERM) 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: else:
os.kill(child.pid, signal.SIGTERM) os.kill(child.pid, signal.SIGTERM)
time.sleep(3) time.sleep(3)