Linux
On Linux, there are two standard types of locking: advisory locking (specified in POSIX) and mandatory locking (for Linux).
However, both of them can be applied only to files, but not to directories. So yes, you need a lock file. It is assumed that all users should be aware of the locked file and obtain a lock before accessing the directory. Therefore, a mandatory lock will not help here, and you need an advisory lock.
There are three types of file locks on Linux:
flock(2) (indicated in POSIX);- POSIX write lock, see the section "Secret Record of Reports" in
fcntl(2), as well as lockf(3)wrapper (both specified in POSIX); - , .
fcntl(2) ( Linux, ).
Python
Python, flock(), lockf() fcntl() fcntl. flock , - fcntl.flock.
:
import flock
with open('/my/dir/lockfile', 'w') as fp:
with flock.Flock(fp, flock.LOCK_EX) as lock:
pass
PS.
, . , , FUSE, , .