Skip to content

Commit 3e9ab2e

Browse files
committed
offload tar build to thread pool
1 parent febccd4 commit 3e9ab2e

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

verifiers/envs/experimental/sandbox_mixin.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,21 @@ async def upload_bundle(
297297
Builds a tar.gz archive from ``file_map`` (relative path → UTF-8
298298
content), uploads it, and extracts into ``dest_dir``.
299299
"""
300-
buf = io.BytesIO()
301-
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
302-
for rel_path, content in file_map.items():
303-
data = content.encode("utf-8")
304-
info = tarfile.TarInfo(name=rel_path)
305-
info.size = len(data)
306-
tar.addfile(info, io.BytesIO(data))
307-
bundle_bytes = buf.getvalue()
308300

301+
def build_tar() -> str:
302+
buf = io.BytesIO()
303+
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
304+
for rel_path, content in file_map.items():
305+
data = content.encode("utf-8")
306+
info = tarfile.TarInfo(name=rel_path)
307+
info.size = len(data)
308+
tar.addfile(info, io.BytesIO(data))
309+
with tempfile.NamedTemporaryFile(delete=False, suffix=".tar.gz") as f:
310+
f.write(buf.getvalue())
311+
return f.name
312+
313+
tmp_path = await asyncio.to_thread(build_tar)
309314
archive_remote = f"{dest_dir}/_bundle.tar.gz"
310-
with tempfile.NamedTemporaryFile(delete=False, suffix=".tar.gz") as f:
311-
f.write(bundle_bytes)
312-
tmp_path = f.name
313315
try:
314316
await self.upload_file(sandbox_id, archive_remote, tmp_path)
315317
finally:

0 commit comments

Comments
 (0)