[Python-Dev] Does Python need a file locking module (slightly higher level)?

skip at pobox.com skip at pobox.com
Mon Oct 22 14:15:45 CEST 2007


I'm always daunted by the prospect of trying to implement file locking.
This just came up again in SpamBayes where we have never protected our
pickle files from corruption when multiple processes access them
simultaneously.  The presence of networked file systems and
platform-independent locks make it a nasty little problem.  Maybe I'm just
showing my age.  Does fcntl.flock work over NFS and SMB and on Windows?  If
this is still as much of a mess as I remember, should Python provide a
simple file locking module in the standard distribution?

Side note: While reading the fcntl man page on my Mac I came across this
text in the description of F_GETLK/F_SETLK/F_SETLKW.

    This interface follows the completely stupid semantics of System V and
    IEEE Std 1003.1-1988 (``POSIX.1'') that require that all locks
    associated with a file for a given process are removed when any file
    descriptor for that file is closed by that process....  Flock(2) is
    recommended for applications that want to ensure the integrity of their
    locks when using library routines or wish to pass locks to their
    children.

I guess the BSD folks were a bit upset when they wrote that.

Skip


More information about the Python-Dev mailing list