INNER CODE UNIT · Python

atomic_write_json

dedsec1121fk/DedSec · Scripts/DedSec Market.py:207

def atomic_write_json(path, data):
    path = Path(path)
    path.parent.mkdir(parents=True, exist_ok=True)
    temp_path = path.with_name(path.name + ".tmp")
    try:
        with temp_path.open("w", encoding="utf-8") as f:
            json.dump(data, f, indent=2, ensure_ascii=False)
            f.flush()
            os.fsync(f.fileno())
        os.replace(temp_path, path)
    finally:
        if temp_path.exists():
            temp_path.unlink(missing_ok=True)


def save_state(state):
    ensure_data_dir()
    atomic_write_json(STATE_FILE, state)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…