Question: posix fcntl module

Ignacio Vazquez-Abrams ignacio at openservices.net
Tue Aug 28 17:52:44 EDT 2001


On Tue, 28 Aug 2001, Sheila King wrote:

> I have a question about file locking aspect of the fcntl module for Unix
> systems.
>
> 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):
>
> NOTES
>        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?).
>
> Please advise. Thanks,
>
> --
> Sheila King
> http://www.thinkspot.net/sheila/
> http://www.k12groups.org/

Yes. Funny thing is, that if the OS doesn't have flock(), it'll use the
lockf()-equivalent fcntl anyways. If you didn't understand that, then don't
worry about it :)

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list