Skip to content

Commit

Permalink
Fix multiprocess writing issue in dints (#378)
Browse files Browse the repository at this point in the history
Add filelock when export config file.
fix #737

Signed-off-by: YunLiu <[email protected]>
  • Loading branch information
KumoLiu authored Apr 23, 2024
1 parent 4403f94 commit 3144342
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion auto3dseg/algorithm_templates/dints/scripts/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import torch
import torch.distributed as dist
from pathlib import Path
from filelock import FileLock

import monai
from monai import transforms
Expand Down Expand Up @@ -131,7 +132,10 @@ def pre_operation(config_file, **override):
parser["training"].update({"num_epochs": int(_estimated_epochs / float(batch_size))})
rank = int(os.getenv("RANK", "0"))
if rank == 0:
ConfigParser.export_config_file(parser.get(), _file, fmt="yaml", default_flow_style=None)
lock = FileLock(f"{_file}.lock")
with lock:
ConfigParser.export_config_file(parser.get(), _file, fmt="yaml", default_flow_style=None)
os.remove(f"{_file}.lock")

return parser

Expand Down

0 comments on commit 3144342

Please sign in to comment.