file locking (was Re: fcntl example)

Andy Bensky (
Mon, 16 May 1994 14:24:57 -0700

> >File locking is not in the standard file object because it's not the
> >same across different UNIX platforms. Now that we have the configure
> >script, I suppose someone could figure out how to do it on SYSV and
> >BSD and add some ifdef'ed code that implements simple file-level
> >locking using a consistent interface to Python users. (Could a BSD
> >version be done in Python?)
> I propose an interface as implemented in my posixfile module. It

Yeah! I am much in favor of a (somewhat)platform-independent implementation
in the standard distribution. Good Work!

> allows arbitrary file locks, including sections of a file. How this
> exactly translates to BSD I forgot, but I'm sure it can be made
> compatible.
> To refresh you memory, here's the introduction to the module:

Is posixfile in the distribution? I haven't seen it referred to before
and I do not see it in the 1.0.1 or 1.0.2 distributions. I do have the
posix and posixpath modules, but the posixfile.file() and
posixfile.flags() functions are not in either one of these. The other
functions descibed here as belonging to posixfile (dup() and dup2()) are
in the posix module in both 1.0.1 and 1.0.2, along with a number of other
file manipulating functions.

> #
> # Extended file operations
> #
> # f =, mode)
> #
> # f.file()
> # will return the original builtin file object
> *** This used to be necessary for marshal.dump() et al., but
> I'm not sure it's still necessary...

I think it is a greast idea to have this function. I wish I had it now.
The reason is that sometimes you want to do complex operations like
flock(), fcntl(), dup(), etc... in which case you need the posixfile type
of interface. But sometimes it is much easier to simply do an f.readlines()
on an open file object. The interface proposed here would allow for both.
Please leave it in!

andy bensky
InfoSeek Corp.