Skip to content

Commit 43e6d64

Browse files
committed
Guard benchmark runner with __main__
1 parent 57c6158 commit 43e6d64

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

benchmarks/suites/base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,12 @@ def _run_script(self, threads: int, mpi_procs: Optional[int]) -> OpenMCRunResult
319319
script_path.write_text(
320320
f"import json\n"
321321
f"import importlib\n"
322-
f"mod = importlib.import_module({self._module_path!r})\n"
323-
f"metrics = mod.run_benchmark(threads={threads!r}, mpi_procs={mpi_procs!r})\n"
324-
f"if metrics is not None:\n"
325-
f" with open({str(metrics_path)!r}, 'w') as fh:\n"
326-
f" json.dump(metrics, fh)\n"
322+
f"if __name__ == '__main__':\n"
323+
f" mod = importlib.import_module({self._module_path!r})\n"
324+
f" metrics = mod.run_benchmark(threads={threads!r}, mpi_procs={mpi_procs!r})\n"
325+
f" if metrics is not None:\n"
326+
f" with open({str(metrics_path)!r}, 'w') as fh:\n"
327+
f" json.dump(metrics, fh)\n"
327328
)
328329

329330
env = OpenMCRunner._build_environment(

0 commit comments

Comments
 (0)