Question: posix fcntl module

Mats Wichmann mats at
Thu Aug 30 00:18:17 CEST 2001

On Tue, 28 Aug 2001 21:25:51 GMT, Sheila King <sheila at>

:I have a question about file locking aspect of the fcntl module for Unix
:I was checking out the man pages on the Linux system that I use (my
:webhost), and under man flock(2) it mentions (among other things):
:       flock(2) does not  lock  files  over  NFS.   Use  fcntl(2)
:       instead:  that  does  work  over NFS, given a sufficiently
:       recent version of Linux and a server which supports  locking.
:       flock(2)  and fcntl(2) locks have different semantics with
:       respect to forked processes and dup(2).
:Python docs for the fcntl module state:
:lockf(fd, operation, [len, [start, [whence]]])
:	This is essentially a wrapper around the fcntl() locking calls. 
:	fd is the file descriptor of the file to lock or unlock, and...
:Am I correct, then, in interpreting these together, to mean, that I will
:get greater portability/control if I use fcntl.lockf than if I use
:fcntl.flock? Because, as I read this, fcntl.lockf may work in situations
:where fcntl.flock does not (especially over NFS?).

while 1:
    print "don't do locks over NFS!"

This position may POSSIBLY be able to be softened for NFS V4.
Mats Wichmann

More information about the Python-list mailing list