Skip to main content

lock

Locks a specified file region on Windows systems using the Win32 API. This function retrieves the operating system file handle and invokes LockFileEx to apply the provided locking flags, returning a boolean indicating success.

def lock(
f: file_descriptor_or_object,
flags: int
) - > boolean

Locks a specified region of a file using the Windows LockFileEx API to manage concurrent access.

Parameters

NameTypeDescription
ffile_descriptor_or_objectThe file object or file descriptor to be locked.
flagsintBitwise flags determining the lock mode, such as LOCKFILE_EXCLUSIVE_LOCK or LOCKFILE_FAIL_IMMEDIATELY.

Returns

TypeDescription
booleanTrue if the lock was successfully acquired, False otherwise.