Skip to content

Commit

Permalink
Open run.log and run.err in binary mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed May 15, 2024
1 parent 7f6bfda commit 5d72b18
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
12 changes: 12 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changelog
=========

v8.3 (unreleased)
-----------------

Lab
^^^
* Open ``run.log`` and ``run.err`` in binary mode to avoid decoding byte strings (Jendrik Seipp).

Downward Lab
^^^^^^^^^^^^
* No changes


v8.2 (2024-05-06)
-----------------

Expand Down
2 changes: 1 addition & 1 deletion examples/downward/2020-09-11-B-bounded-cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
algo_name = f"{rev_nick}-{config_nick}" if rev_nick else config_nick

bounds = {}
with open(BOUNDS_FILE) as f:
with open(BOUNDS_FILE, "rb") as f:
bounds = json.load(f)
for task in suites.build_suite(BENCHMARKS_DIR, SUITE):
upper_bound = bounds[f"{task.domain}:{task.problem}"]
Expand Down
6 changes: 2 additions & 4 deletions lab/calls/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import sys
import time

from lab import tools


def set_limit(kind, soft_limit, hard_limit):
try:
Expand Down Expand Up @@ -59,7 +57,7 @@ def get_bytes(limit):
for stream_name in ["stdout", "stderr"]:
stream = kwargs.get(stream_name)
if isinstance(stream, str):
file = open(stream, mode="w")
file = open(stream, mode="wb")
kwargs[stream_name] = file
self.opened_files.append(file)

Expand Down Expand Up @@ -169,7 +167,7 @@ def close_unregister_and_remove(fd):
self.process.terminate()
# Strip extra bytes.
data = data[: hard_limit - fd_to_bytes[fd]]
outfile.write(tools.get_string(data))
outfile.write(data)
fd_to_bytes[fd] += len(data)
else:
# Ignore hang up or errors.
Expand Down
4 changes: 2 additions & 2 deletions lab/data/run.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ tools.configure_logging()

logging.info(f"node: {platform.node()}")

run_log = open("run.log", "w")
run_err = open("run.err", "w", buffering=1) # line buffering
run_log = open("run.log", "wb")
run_err = open("run.err", "wb", buffering=0) # disable buffering
redirects = {"stdout": run_log, "stderr": run_err}

# Make sure we're in the run directory.
Expand Down

0 comments on commit 5d72b18

Please sign in to comment.