Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-285-Cancel-execution-may-leave-running-processes de0b05d39 -> 1f770c22b (forced update)
fixed test waitinge Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1f770c22 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1f770c22 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1f770c22 Branch: refs/heads/ARIA-285-Cancel-execution-may-leave-running-processes Commit: 1f770c22bfcbc173131818888712e31f03d9f60f Parents: 3d5efc4 Author: max-orlov <[email protected]> Authored: Tue Jun 27 11:53:40 2017 +0300 Committer: max-orlov <[email protected]> Committed: Tue Jun 27 12:49:42 2017 +0300 ---------------------------------------------------------------------- aria/orchestrator/workflows/executor/process.py | 19 ++++++++----------- .../workflows/executor/test_process_executor.py | 10 ++++++---- 2 files changed, 14 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f770c22/aria/orchestrator/workflows/executor/process.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py index 92c83e3..389373b 100644 --- a/aria/orchestrator/workflows/executor/process.py +++ b/aria/orchestrator/workflows/executor/process.py @@ -125,14 +125,8 @@ 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 - if task and os.getsid(os.getpid()) != os.getpgid(task.proc.pid): - # 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) + if task: + os.killpg(os.getpgid(task.proc.pid), signal.SIGKILL) def _execute(self, ctx): self._check_closed() @@ -146,10 +140,13 @@ class ProcessExecutor(base.BaseExecutor): env = self._construct_subprocess_env(task=ctx.task) # Asynchronously start the operation in a subprocess proc = subprocess.Popen( - '{0} {1} {2}'.format(sys.executable, __file__, arguments_json_path), + [ + sys.executable, + os.path.expanduser(os.path.expandvars(__file__)), + os.path.expanduser(os.path.expandvars(arguments_json_path)) + ], env=env, - preexec_fn=os.setsid, - shell=True) + preexec_fn=os.setsid) self._tasks[ctx.task.id] = _Task(ctx=ctx, proc=proc) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f770c22/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 be3e833..01aff17 100644 --- a/tests/orchestrator/workflows/executor/test_process_executor.py +++ b/tests/orchestrator/workflows/executor/test_process_executor.py @@ -90,12 +90,13 @@ class TestProcessExecutor(object): executor.execute(ctx) - while fs_test_holder.get('subproc', None) is None: - time.sleep(1) - pids = [executor._tasks[ctx.task.id].proc.pid, fs_test_holder['subproc']] + @retrying.retry(retry_on_result=lambda r: r is False, stop_max_delay=10000, wait_fixed=500) + def wait_for_extra_process_id(): + return fs_test_holder.get('subproc', False) + + pids = [executor._tasks[ctx.task.id].proc.pid, wait_for_extra_process_id()] 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) @@ -135,6 +136,7 @@ def model(tmpdir): @operation def freezing_task(holder_path, **_): + import pydevd; pydevd.settrace('localhost', suspend=False) holder = FilesystemDataHolder(holder_path) holder['subproc'] = subprocess.Popen('while true; do sleep 5; done', shell=True).pid while True:
