I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.
from filelock import FileLock with FileLock("myfile.txt.lock"): print("Lock acquired.") with open("myfile.txt"): # work with the file as it is now locked