core.files.lock

core.files.lock.LockFile(locked_file: Path, ext='.lock', interval=1, timeout=0, create_dir=True)[source]

Create a blocking context with a lock file

timeout: timeout in seconds, waiting to the lock to be released.

If negative, disable lock files entirely.

interval: interval in seconds

Example

with LockFile(‘/dir/to/file.txt’):

# create a file ‘/dir/to/file.txt.lock’ including a filesystem lock # the context will enter once the lock is released