diff options
Diffstat (limited to 'debug/risc-v-gsp-rm-vm/harness/value_demos/_common.py')
| -rw-r--r-- | debug/risc-v-gsp-rm-vm/harness/value_demos/_common.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/debug/risc-v-gsp-rm-vm/harness/value_demos/_common.py b/debug/risc-v-gsp-rm-vm/harness/value_demos/_common.py index 0733c48..ebbc390 100644 --- a/debug/risc-v-gsp-rm-vm/harness/value_demos/_common.py +++ b/debug/risc-v-gsp-rm-vm/harness/value_demos/_common.py @@ -17,6 +17,7 @@ import json import os import shutil import sys +import tempfile import time HERE = os.path.dirname(os.path.abspath(__file__)) @@ -95,11 +96,24 @@ def artifact_dir(name: str) -> str: return path +def session_dir(root: str, label: str = "session") -> str: + """A unique recording dir under ``root``. + + Demos share a fixed artifact root so their reports are discoverable, but + two concurrent demo runs (tests, agents) must never share one + ``events.jsonl`` or a reader can see a half-written recording. + """ + os.makedirs(root, exist_ok=True) + return tempfile.mkdtemp(prefix=f"{label}-", dir=root) + + def write_json(path: str, payload) -> str: os.makedirs(os.path.dirname(path), exist_ok=True) - with open(path, "w", encoding="utf-8") as fh: + tmp = f"{path}.tmp-{os.getpid()}" + with open(tmp, "w", encoding="utf-8") as fh: json.dump(payload, fh, indent=2, sort_keys=True) fh.write("\n") + os.replace(tmp, path) return path |
