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
filelockpackage 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
pathwill 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:
- path
str The path to acquire a lock for (and optionally open).
- *args
tuple Additional positional arguments forwarded to
open.- lock_timeout
float|None Timeout in seconds for acquiring the lock. If
None, the default timeout applies.- lock
bool If True, use a FileLock (if available) to lock the file.
- **kwargs
dict Additional keyword arguments forwarded to
open.
- path
- Yields: