I'm trying to write a binary file and lock access for other processes until the file has fully written on the disk. I'm working on Windows OS. The interesting thing is that the code working OK if I write small files (~1KB), but when I'm trying to write bigger files, Python is raising the error:
PermissionError: [Errno 13] Permission denied.
with open(full_file_name, "wb") as f:
lock = FileLock(full_file_name)
with lock:
f.write(bytearray(array))
You should use "~.lock" file to lock file.
lock = FileLock(full_file_name + ".lock")
with lock:
with open(full_file_name, "wb") as f:
f.write(bytearray(array))
Please check sample code of official document at PyPi in detail: https://pypi.org/project/filelock/