Skip to content

Commit

Permalink
write to tmp file and move for yaml changes to ensure a good state in…
Browse files Browse the repository at this point in the history
… case of multiple processes
  • Loading branch information
wjblanke authored and hoffmang9 committed Jul 16, 2020
1 parent a0eb152 commit e2cf06c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pkg_resources
import sys
import yaml
import shutil
import os

from pathlib import Path
from typing import Dict, Any, Callable, Optional, Union
Expand Down Expand Up @@ -33,8 +35,9 @@ def config_path_for_filename(root_path: Path, filename: Union[str, Path]) -> Pat

def save_config(root_path: Path, filename: Union[str, Path], config_data: Any):
path = config_path_for_filename(root_path, filename)
with open(path, "w") as f:
with open(path.with_suffix('.' + str(os.getpid())), "w") as f:
yaml.safe_dump(config_data, f)
shutil.move(path.with_suffix('.' + str(os.getpid())), path)


def load_config(
Expand Down

0 comments on commit e2cf06c

Please sign in to comment.