From 4a4d884fdfd55c7bbf76110c8f80e0a655b514aa Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Wed, 22 Apr 2026 10:23:09 -0700 Subject: [PATCH] Passthrough for `subprocess.Popen` in `start_cancellable_process` --- compiler_opt/rl/compilation_runner.py | 17 +++++++++++------ compiler_opt/rl/compilation_runner_test.py | 12 +++++++----- compiler_opt/rl/inlining/inlining_runner.py | 8 ++++---- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/compiler_opt/rl/compilation_runner.py b/compiler_opt/rl/compilation_runner.py index 3d48213c..bdd50e77 100644 --- a/compiler_opt/rl/compilation_runner.py +++ b/compiler_opt/rl/compilation_runner.py @@ -208,11 +208,14 @@ def __del__(self): raise RuntimeError('Cancellation manager deleted while containing items.') -def start_cancellable_process(cmdline: list[str], - timeout: float, - cancellation_manager: WorkerCancellationManager - | None, - want_output: bool = False) -> bytes | None: +def start_cancellable_process( + cmdline: list[str], + timeout: float, + cancellation_manager: WorkerCancellationManager + | None, + want_output: bool = False, + **kwargs, +) -> bytes | str | None: """Start a cancellable process. Args: @@ -237,7 +240,9 @@ def start_cancellable_process(cmdline: list[str], with subprocess.Popen( cmdline, env=command_env, - stdout=(subprocess.PIPE if want_output else None)) as p: + stdout=(subprocess.PIPE if want_output else None), + **kwargs, + ) as p: if cancellation_manager: cancellation_manager.register_process(p) diff --git a/compiler_opt/rl/compilation_runner_test.py b/compiler_opt/rl/compilation_runner_test.py index 874b9cbc..011c8110 100644 --- a/compiler_opt/rl/compilation_runner_test.py +++ b/compiler_opt/rl/compilation_runner_test.py @@ -217,11 +217,13 @@ def test_exception_handling(self, mock_compile_fn): def test_start_subprocess_output(self): cm = compilation_runner.WorkerCancellationManager() - output = compilation_runner.start_cancellable_process( - ['ls', '-l'], timeout=100, cancellation_manager=cm, want_output=True) - if output: - output_str = output.decode('utf-8') - else: + output_str = compilation_runner.start_cancellable_process( + ['ls', '-l'], + timeout=100, + cancellation_manager=cm, + want_output=True, + text=True) + if not output_str: self.fail('output should have been non-empty') self.assertNotEmpty(output_str) diff --git a/compiler_opt/rl/inlining/inlining_runner.py b/compiler_opt/rl/inlining/inlining_runner.py index 2fbb41a6..54332ee8 100644 --- a/compiler_opt/rl/inlining/inlining_runner.py +++ b/compiler_opt/rl/inlining/inlining_runner.py @@ -97,14 +97,14 @@ def compile_and_get_size(self, command_line: corpus.FullyQualifiedCmdLine, self._compilation_timeout, self._cancellation_manager) cmdline = [self._llvm_size_path, output_native_path] - output_bytes = compilation_runner.start_cancellable_process( + output = compilation_runner.start_cancellable_process( cmdline, timeout=self._compilation_timeout, cancellation_manager=self._cancellation_manager, - want_output=True) - if not output_bytes: + want_output=True, + text=True) + if not output: raise RuntimeError(f'Empty llvm-size output: {" ".join(cmdline)}') - output = output_bytes.decode('utf-8') tmp = output.split('\n') if len(tmp) != 3: raise RuntimeError(f'Wrong llvm-size output {output}')