write to the same file from multiple processes at the same time?

Grant Edwards grante at visi.com
Fri May 27 10:50:04 EDT 2005


On 2005-05-27, Peter Hansen <peter at engcorp.com> wrote:
> Roy Smith wrote:
>> gabor <gabor at nekomancer.net> wrote:
>> On the other hand, you said that each process will be writing a single line 
>> of output at a time.  If you call flush() after each message is written, 
>> that should be enough to ensure that the each line gets written in a single 
>> write system call, which in turn should be good enough to ensure that 
>> individual lines of output are not scrambled in the log file.
>
> Unfortunately this assumes that the open() call will always succeed, 
> when in fact it is likely to fail sometimes when another file has 
> already opened the file but not yet completed writing to it, AFAIK.

Not in my experience.  At least under Unix, it's perfectly OK
to open a file while somebody else is writing to it.  Perhaps
Windows can't deal with that situation?

-- 
Grant Edwards                   grante             Yow!  FOOLED you! Absorb
                                  at               EGO SHATTERING impulse
                               visi.com            rays, polyester poltroon!!



More information about the Python-list mailing list