mne_bids.open_lock#

mne_bids.open_lock(path, *args, lock_timeout=None, lock=True, **kwargs)#

Context manager that acquires a file lock with optional file opening.

If the filelock package is available, a lock is acquired on a lock file based on the given path (by appending ‘.lock’). Lock files are left behind to avoid race conditions during concurrent operations.

The lock is re-entrant per process: nested calls for the same path will reuse the existing lock instead of attempting to acquire it again.

If file opening arguments (*args, **kwargs) are provided, the file is opened in the specified mode. Otherwise, just the lock is acquired.

Parameters:
pathstr

The path to acquire a lock for (and optionally open).

*argstuple

Additional positional arguments forwarded to open.

lock_timeoutfloat | None

Timeout in seconds for acquiring the lock. If None, the default timeout applies.

lockbool

If True, use a FileLock (if available) to lock the file.

**kwargsdict

Additional keyword arguments forwarded to open.

Yields:
fidio.IOBase | None

File object if file opening args were provided, None otherwise.