Lock a file. Note that this is an advisory lock on Linux/Unix systems
Unlock a file
Place an exclusive lock. Only one process may hold an exclusive lock for a given file at a given time.
Place a shared lock. More than one process may hold a shared lock for a given file at a given time.
Acquire the lock in a non-blocking fashion.
Remove an existing lock held by this process.
Bases: portalocker.exceptions.BaseLockException
Exception thrown if an error occurred during locking
Locking utility class to automatically handle opening with timeouts and context wrappers
Bases: portalocker.exceptions.BaseLockException
Exception thrown when the file is already locked by someone else
Open a file for atomic writing. Instead of locking this method allows you to write the entire file and move it to the actual location. Note that this makes the assumption that a rename is atomic on your platform which is generally the case but not a guarantee.
http://docs.python.org/library/os.html#os.rename
>>> filename = 'test_file.txt'
>>> if os.path.exists(filename):
... os.remove(filename)
>>> with open_atomic(filename) as fh:
... written = fh.write(b'test')
>>> assert os.path.exists(filename)
>>> os.remove(filename)