File I/O module.
- exception wmflib.fileio.FileIOError¶
Custom exception class for errors of the BlockInFile class.
- exception wmflib.fileio.LockError¶
Custom exception class raised when unable to exclusively lock a file.
- wmflib.fileio.locked_open(file_path: pathlib.Path, file_mode: str = 'r', *, timeout: int = 10) Generator[IO, None, None] ¶
Context manager to open a file with an exclusive lock on it and a retry logic.
file_path (pathlib.Path) – the file path to open.
timeout (int, optional) – the total timeout in seconds to wait to acquire the exclusive lock before giving up. Ten tries will be attempted to acquire the lock within the timeout.
wmflib.fileio.LockError – on failure to acquire the exclusive lock on the file.
file object – the open file with an exclusive lock on it.