Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-285-Cancel-execution-may-leave-running-processes 9d2059982 -> 
3d5efc43f


wip


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/3d5efc43
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/3d5efc43
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/3d5efc43

Branch: refs/heads/ARIA-285-Cancel-execution-may-leave-running-processes
Commit: 3d5efc43f307f081f8628732d2ff93a8f15f440e
Parents: 9d20599
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Jun 27 11:16:53 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Tue Jun 27 11:16:53 2017 +0300

----------------------------------------------------------------------
 aria/logger.py                                                | 3 ++-
 aria/orchestrator/workflows/executor/process.py               | 5 +++++
 .../orchestrator/workflows/executor/test_process_executor.py  | 7 ++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3d5efc43/aria/logger.py
----------------------------------------------------------------------
diff --git a/aria/logger.py b/aria/logger.py
index bd7ed4e..6094f75 100644
--- a/aria/logger.py
+++ b/aria/logger.py
@@ -48,7 +48,7 @@ class LoggerMixin(object):
     logger_name = None
     logger_level = logging.DEBUG
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, termination_timeout=10, *args, **kwargs):
         self.logger_name = self.logger_name or self.__class__.__name__
         self.logger = logging.getLogger('{0}.{1}'.format(_base_logger.name, 
self.logger_name))
         # Set the logger handler of any object derived from LoggerMixing to 
NullHandler.
@@ -56,6 +56,7 @@ class LoggerMixin(object):
         # `No handlers could be found for logger "..."`.
         self.logger.addHandler(NullHandler())
         self.logger.setLevel(self.logger_level)
+        self._termination_timeout = termination_timeout
         super(LoggerMixin, self).__init__(*args, **kwargs)
 
     @classmethod

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3d5efc43/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py 
b/aria/orchestrator/workflows/executor/process.py
index 0600b6a..92c83e3 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -29,6 +29,8 @@ from collections import namedtuple
 
 import signal
 
+import time
+
 script_dir = os.path.dirname(__file__)
 if script_dir in sys.path:
     sys.path.remove(script_dir)
@@ -127,6 +129,9 @@ class ProcessExecutor(base.BaseExecutor):
             # If the above condition is false, the process group leader is the 
group leader
             # for the current session of the system, and killing it will kill 
the the entire
             # os session.
+            os.killpg(os.getpgid(task.proc.pid), signal.SIGINT)
+
+            time.sleep(self._termination_timeout)
             os.killpg(os.getpgid(task.proc.pid), signal.SIGTERM)
 
     def _execute(self, ctx):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3d5efc43/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 963b7a8..be3e833 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor.py
@@ -20,6 +20,7 @@ import subprocess
 
 import pytest
 import psutil
+import retrying
 
 import aria
 from aria import operation
@@ -94,6 +95,7 @@ class TestProcessExecutor(object):
         pids = [executor._tasks[ctx.task.id].proc.pid, 
fs_test_holder['subproc']]
         assert any(p.pid == pid for p in psutil.process_iter() for pid in pids)
         executor.terminate(ctx.task.id)
+        time.sleep(10)
         assert not any(p.pid == pid and p.status() != psutil.STATUS_ZOMBIE
                        for p in psutil.process_iter()
                        for pid in pids)
@@ -108,7 +110,10 @@ def fs_test_holder(tmpdir):
 
 @pytest.fixture
 def executor(plugin_manager):
-    result = process.ProcessExecutor(plugin_manager=plugin_manager, 
python_path=[tests.ROOT_DIR])
+    result = process.ProcessExecutor(
+        plugin_manager=plugin_manager,
+        python_path=[tests.ROOT_DIR],
+        termination_timeout=1)
     yield result
     result.close()
 

Reply via email to