duck.utils.filelock¶
File lock capabilities module.
Module Contents¶
Functions¶
Lock file when modifying or accessing critical sections to avoid race conditions. |
|
Opens a file and acquires an exclusive lock. |
|
Unlock a locked file. |
API¶
- duck.utils.filelock.lock_file(file_descriptor, retries=5, wait=1)[source]¶
Lock file when modifying or accessing critical sections to avoid race conditions.
- duck.utils.filelock.open_and_lock(filename, mode='r+', failsafe: bool = True)[source]¶
Opens a file and acquires an exclusive lock.
- Parameters:
filename – The name of the file to open.
mode – The file open mode (default is ‘r+’).
failsafe – Whether to continue if file locking fails.
- Returns:
The opened file object.