[Twisted-Python] twisted.lumberjack clobbers existing logs
Andreas Kostyrka
andreas at mtg.co.at
Wed Feb 27 02:22:20 MST 2002
> On Mon, Feb 25, 2002 at 05:27:33PM +0000, Itamar Shtull-Trauring wrote:
> >
> >
> > # assuming "file" exists
> >
> > f = open("file", "r+")
> >
> > f.seek(0, 2)
> >
> > see the code I checked in for a complete example.
Well, this assumes that there is only one writer for the file.
O_APPEND OTOH, when implemented in the kernel (and not emulated
with the above code in the library), makes this as ONE atomic call.
(basically, it seeks to the end of the file before any write).
>From open(2):
O_APPEND
The file is opened in append mode. Before each
write, the file pointer is positioned at the end of
the file, as if with lseek. O_APPEND may lead to
corrupted files on NFS file systems if more than
one process appends data to a file at once. This
is because NFS does not support appending to a
file, so the client kernel has to simulate it,
which can't be done without a race condition.
Basically, in the NFS case the kernel is not able to do it atomic
so there might be problems.
Side note: It's quite acceptable to use seek/read with an O_RDWR|O_APPEND file.
It's just automatically seeks to the end before writing. So O_APPEND is quite useful.
Andreas
More information about the Twisted-Python
mailing list