duck.utils.filelock

File lock capabilities module.

Module Contents

Functions

lock_file

Lock file when modifying or accessing critical sections to avoid race conditions.

open_and_lock

Opens a file and acquires an exclusive lock.

unlock_file

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.

duck.utils.filelock.unlock_file(file_descriptor)[source]

Unlock a locked file.