ariatosca-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject incubator-ariatosca git commit: added psutil to project [Forced Update!]
Date Tue, 27 Jun 2017 13:28:58 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-285-Cancel-execution-may-leave-running-processes 6606f80e0 -> dc23376a5
(forced update)


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/dc23376a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/dc23376a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/dc23376a

Branch: refs/heads/ARIA-285-Cancel-execution-may-leave-running-processes
Commit: dc23376a504b875c3e21e121f776131b40cfd1c4
Parents: b019de6
Author: max-orlov <maxim@gigaspaces.com>
Authored: Tue Jun 27 16:09:17 2017 +0300
Committer: max-orlov <maxim@gigaspaces.com>
Committed: Tue Jun 27 16:28:53 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/workflows/core/engine.py       |  8 +++++---
 aria/orchestrator/workflows/executor/process.py  | 19 ++++++++++++++-----
 requirements.in                                  |  1 +
 requirements.txt                                 |  1 +
 .../workflows/executor/test_process_executor.py  |  2 +-
 5 files changed, 22 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/dc23376a/aria/orchestrator/workflows/core/engine.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/engine.py b/aria/orchestrator/workflows/core/engine.py
index 5d6fcd7..7d4fe04 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 e
 
     def _terminate_tasks(self, tasks):
         for task in tasks:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/dc23376a/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py
index 278e764..59e61b6 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 BaseException:
+                        pass
+                parent_process.send_signal(signal.SIGKILL)
+            except BaseException:
+                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/dc23376a/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/dc23376a/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

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/dc23376a/tests/orchestrator/workflows/executor/test_process_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_process_executor.py b/tests/orchestrator/workflows/executor/test_process_executor.py
index 746ed93..6f5c827 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor.py
@@ -98,7 +98,7 @@ class TestProcessExecutor(object):
         assert any(p.pid == pid for p in psutil.process_iter() for pid in pids)
         executor.terminate(ctx.task.id)
 
-        # Give a change to the processes to terminate
+        # Give a chance to the processes to terminate
         time.sleep(2)
         assert not any(p.pid == pid and p.status() != psutil.STATUS_ZOMBIE
                        for p in psutil.process_iter()


Mime
View raw message