You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ariatosca.apache.org by mx...@apache.org on 2017/06/27 13:09:23 UTC
incubator-ariatosca git commit: added psutil to project
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-285-Cancel-execution-may-leave-running-processes b019de64e -> 169aa3e77
added psutil to project
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/169aa3e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/169aa3e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/169aa3e7
Branch: refs/heads/ARIA-285-Cancel-execution-may-leave-running-processes
Commit: 169aa3e77bf946a1b0a3c53e0f0a160de18fb1f4
Parents: b019de6
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Jun 27 16:09:17 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Tue Jun 27 16:09:17 2017 +0300
----------------------------------------------------------------------
aria/orchestrator/workflows/core/engine.py | 8 +++++---
aria/orchestrator/workflows/executor/process.py | 19 ++++++++++++++-----
requirements.in | 1 +
requirements.txt | 1 +
4 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/169aa3e7/aria/orchestrator/workflows/core/engine.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/engine.py b/aria/orchestrator/workflows/core/engine.py
index 5d6fcd7..c47fbe3 100644
--- a/aria/orchestrator/workflows/core/engine.py
+++ b/aria/orchestrator/workflows/core/engine.py
@@ -74,9 +74,11 @@ class Engine(logger.LoggerMixin):
events.on_success_workflow_signal.send(ctx)
except BaseException as e:
# Cleanup any remaining tasks
- self._terminate_tasks(tasks_tracker.executing_tasks)
- events.on_failure_workflow_signal.send(ctx, exception=e)
- raise
+ try:
+ self._terminate_tasks(tasks_tracker.executing_tasks)
+ finally:
+ events.on_failure_workflow_signal.send(ctx, exception=e)
+ raise
def _terminate_tasks(self, tasks):
for task in tasks:
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/169aa3e7/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py
index 278e764..dd2055d 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -25,9 +25,9 @@ import sys
# As part of the process executor implementation, subprocess are started with this module as their
# entry point. We thus remove this module's directory from the python path if it happens to be
# there
-from collections import namedtuple
import signal
+from collections import namedtuple
script_dir = os.path.dirname(__file__)
if script_dir in sys.path:
@@ -43,6 +43,7 @@ import tempfile
import Queue
import pickle
+import psutil
import jsonpickle
import aria
@@ -125,9 +126,18 @@ class ProcessExecutor(base.BaseExecutor):
def terminate(self, task_id):
task = self._tasks.get(task_id)
- # The process might have managed to finished so it would not be in the tasks list
+ # The process might have managed to finish, thus it would not be in the tasks list
if task:
- os.killpg(os.getpgid(task.proc.pid), signal.SIGKILL)
+ try:
+ parent_process = psutil.Process(task.proc.pid)
+ for child_process in reversed(parent_process.children(recursive=True)):
+ try:
+ child_process.send_signal(signal.SIGKILL)
+ except:
+ pass
+ parent_process.send_signal(signal.SIGKILL)
+ except:
+ pass
def _execute(self, ctx):
self._check_closed()
@@ -146,8 +156,7 @@ class ProcessExecutor(base.BaseExecutor):
os.path.expanduser(os.path.expandvars(__file__)),
os.path.expanduser(os.path.expandvars(arguments_json_path))
],
- env=env,
- preexec_fn=os.setsid)
+ env=env)
self._tasks[ctx.task.id] = _Task(ctx=ctx, proc=proc)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/169aa3e7/requirements.in
----------------------------------------------------------------------
diff --git a/requirements.in b/requirements.in
index cecc9fd..f2a9730 100644
--- a/requirements.in
+++ b/requirements.in
@@ -33,6 +33,7 @@ PrettyTable>=0.7,<0.8
click_didyoumean==0.0.3
backports.shutil_get_terminal_size==1.0.0
logutils==0.3.4.1
+psutil==5.2.2
importlib ; python_version < '2.7'
ordereddict ; python_version < '2.7'
total-ordering ; python_version < '2.7' # only one version on pypi
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/169aa3e7/requirements.txt
----------------------------------------------------------------------
diff --git a/requirements.txt b/requirements.txt
index 9f929a9..7ee1008 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -26,6 +26,7 @@ networkx==1.9.1
ordereddict==1.1 ; python_version < "2.7"
packaging==16.8 # via setuptools
prettytable==0.7.2
+psutil==5.2.2
pyparsing==2.2.0 # via packaging
requests==2.13.0
retrying==1.3.3