From d934cdd37d63e33b88d3cac69d973eeea185de70 Mon Sep 17 00:00:00 2001 From: Dan Lord Date: Fri, 30 Aug 2024 11:20:12 -0700 Subject: [PATCH] Resolve an issue when attempting to call decode() on a streamed/potentially temporarily invalid utf-8 string. --- swebench/harness/docker_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/swebench/harness/docker_utils.py b/swebench/harness/docker_utils.py index 45a064b3..1ab186b3 100644 --- a/swebench/harness/docker_utils.py +++ b/swebench/harness/docker_utils.py @@ -183,7 +183,7 @@ def exec_run_with_timeout(container, cmd, timeout: int|None=60): timeout (int): Timeout in seconds. """ # Local variables to store the result of executing the command - exec_result = '' + exec_result = b'' exec_id = None exception = None timed_out = False @@ -195,7 +195,7 @@ def run_command(): exec_id = container.client.api.exec_create(container.id, cmd)["Id"] exec_stream = container.client.api.exec_start(exec_id, stream=True) for chunk in exec_stream: - exec_result += chunk.decode() + exec_result += chunk except Exception as e: exception = e @@ -215,7 +215,7 @@ def run_command(): container.exec_run(f"kill -TERM {exec_pid}", detach=True) timed_out = True end_time = time.time() - return exec_result, timed_out, end_time - start_time + return exec_result.decode(), timed_out, end_time - start_time def find_dependent_images(client: docker.DockerClient, image_name: str):