mne_bids.open_lock#
- mne_bids.open_lock(path, *args, lock_timeout=None, lock=True, **kwargs)[source]#
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’) and held for the wholewithblock. The lock file is removed when the lock is released.If file opening arguments (
*args,**kwargs) are provided, the file is opened in the specified mode. Otherwise, just the lock is acquired. A file opened with"w"or"wb"is written to a temporary file and moved into place at the end of the block, so readers never see it partially written.The lock is re-entrant per thread: a nested call for the same
pathreuses the lock instead of waiting for it. To read a file and then write it, do both inside onewith open_lock(path):block.- 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: