Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions compiler_opt/rl/compilation_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions compiler_opt/rl/compilation_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions compiler_opt/rl/inlining/inlining_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
Loading