Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50460

Re: Concurrent writes to the same file

From Neal Becker <ndbecker2@gmail.com>
Subject Re: Concurrent writes to the same file
Date 2013-07-11 11:58 -0400
References <CANy1k1iCT3O=o6AwrpaZemzup1dQRwq-vpoperegamtB2psbcA@mail.gmail.com> <krlg5i$rqj$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.4593.1373558361.3114.python-list@python.org> (permalink)

Show all headers | View raw


Dave Angel wrote:

> On 07/11/2013 12:57 AM, Jason Friedman wrote:
>> Other than using a database, what are my options for allowing two processes
>> to edit the same file at the same time?  When I say same time, I can accept
>> delays.  I considered lock files, but I cannot conceive of how I avoid race
>> conditions.
>>
> 
> In general, no.  That's what a database is for.
> 
> Now, you presumably have some reason to avoid database, but in its stead
> you have to specify some other limitations.  To start with, what do you
> mean by "the same time"?  If each process can modify the entire file,
> then there's no point in one process reading the file at all until it
> has the lock.  So the mechanism would be
>    1) wait till you can acquire the lock
>    2) open the file, read it, modify it, flush and close
>    3) release the lock
> 
> To come up with an appropriate lock, it'd be nice to start by specifying
> the entire environment.  Which Python, which OS?  Are the two processes
> on the same CPU, what's the file system, and is it locally mounted?
> 
> 
> 
> 

You can use a seperate server process to do file I/O, taking multiple inputs 
from clients.  Like syslogd.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Concurrent writes to the same file Neal Becker <ndbecker2@gmail.com> - 2013-07-11 11:58 -0400

csiph-web