phenotypic.sdk_.atomic_write_text#
- phenotypic.sdk_.atomic_write_text(path: str | Path, text: str, *, encoding: str = 'utf-8', pre_replace: Callable[[], None] | None = None, commit_guard: Callable[[], AbstractContextManager[None]] | None = None) None[source]#
Atomically write
texttopath(temp sibling +os.replace).A drop-in replacement for
Path(path).write_text(text)that never leaves a half-written file: a concurrent reader sees either the old contents or the complete new ones, and an exception mid-write leaves any pre-existing file intact with no.tmpdebris.- Parameters:
text (str) – The full text payload to write.
encoding (str) – The text encoding (default
"utf-8").pre_replace (Callable[[], None] | None) – Optional callback invoked immediately before publication.
commit_guard (Callable[[], AbstractContextManager[None]] | None)
- Raises:
OSError – If the write or rename fails (the temp file is removed first).
- Return type:
None