From 98890e73b5b783b7c920342adbf8257f69a6c076 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Tue, 16 Jun 2026 10:17:31 +0400 Subject: [PATCH 1/3] Switch process creation to subprocess.run() --- esrally/utils/process.py | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/esrally/utils/process.py b/esrally/utils/process.py index a91d463c0..8dc19484b 100644 --- a/esrally/utils/process.py +++ b/esrally/utils/process.py @@ -36,24 +36,22 @@ def run_subprocess(command_line: str) -> int: :param command_line: The command line of the subprocess to launch. :return: The process' return code """ - return subprocess.call(command_line, shell=True) + return subprocess.run(command_line, check=False, shell=True).returncode def run_subprocess_with_output(command_line: str, env: Optional[Mapping[str, str]] = None) -> list[str]: logger = logging.getLogger(__name__) logger.debug("Running subprocess [%s] with output.", command_line) command_line_args = shlex.split(command_line) - with subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) as command_line_process: - has_output = True - lines = [] - while has_output: - assert command_line_process.stdout is not None, "stdout is None" - line = command_line_process.stdout.readline() - if line: - lines.append(line.decode("UTF-8").strip()) - else: - has_output = False - return lines + result = subprocess.run( + command_line_args, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + env=env, + text=True, + check=False, + ) + return [line.rstrip("\n") for line in result.stdout.splitlines()] def exit_status_as_bool(runnable: Callable[[], int], quiet: bool = False) -> bool: @@ -99,22 +97,21 @@ def run_subprocess_with_logging( if header is not None: logger.info(header) - # pylint: disable=subprocess-popen-preexec-fn - with subprocess.Popen( + completed = subprocess.run( command_line_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - universal_newlines=True, + text=True, env=env, stdin=stdin if stdin else None, preexec_fn=pre_exec, - ) as command_line_process: - stdout, _ = command_line_process.communicate() - if stdout: - logger.log(level=level, msg=stdout) + check=False, + ) + if completed.stdout: + logger.log(level=level, msg=completed.stdout) - logger.debug("Subprocess [%s] finished with return code [%s].", command_line, str(command_line_process.returncode)) - return command_line_process.returncode + logger.debug("Subprocess [%s] finished with return code [%s].", command_line, str(completed.returncode)) + return completed.returncode def run_subprocess_with_logging_and_output( From 34a150d4496dd867f8a1c28e1759563ce4272e4f Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Tue, 16 Jun 2026 10:22:23 +0400 Subject: [PATCH 2/3] Stop using unsafe preexec_fn usage --- esrally/utils/process.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/esrally/utils/process.py b/esrally/utils/process.py index 8dc19484b..3b8dd3b30 100644 --- a/esrally/utils/process.py +++ b/esrally/utils/process.py @@ -93,7 +93,6 @@ def run_subprocess_with_logging( logger = logging.getLogger(__name__) logger.debug("Running subprocess [%s] with logging.", command_line) command_line_args = shlex.split(command_line) - pre_exec = os.setpgrp if detach else None if header is not None: logger.info(header) @@ -104,7 +103,7 @@ def run_subprocess_with_logging( text=True, env=env, stdin=stdin if stdin else None, - preexec_fn=pre_exec, + start_new_session=detach, check=False, ) if completed.stdout: @@ -137,7 +136,6 @@ def run_subprocess_with_logging_and_output( logger = logging.getLogger(__name__) logger.debug("Running subprocess [%s] with logging.", command_line) command_line_args = shlex.split(command_line) - pre_exec = os.setpgrp if detach else None if header is not None: logger.info(header) @@ -149,7 +147,7 @@ def run_subprocess_with_logging_and_output( env=env, check=False, stdin=stdin if stdin else None, - preexec_fn=pre_exec, + start_new_session=detach, ) for stdout in completed.stdout.splitlines(): From 1a42e3346c680c458c7473a21bc9ea596b9ec9c1 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Fri, 19 Jun 2026 16:07:09 +0400 Subject: [PATCH 3/3] Specify UTF-8 encoding in subprocess.run() call Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- esrally/utils/process.py | 1 + 1 file changed, 1 insertion(+) diff --git a/esrally/utils/process.py b/esrally/utils/process.py index 3b8dd3b30..783a0de02 100644 --- a/esrally/utils/process.py +++ b/esrally/utils/process.py @@ -49,6 +49,7 @@ def run_subprocess_with_output(command_line: str, env: Optional[Mapping[str, str stderr=subprocess.STDOUT, env=env, text=True, + encoding="utf-8", check=False, ) return [line.rstrip("\n") for line in result.stdout.splitlines()]