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


Groups > comp.lang.python > #50460

Re: Concurrent writes to the same file

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'modify': 0.07; 'subject:file': 0.07; 'subject:same': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '12:57': 0.16; 'flush': 0.16; 'inputs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'seperate': 0.16; 'specifying': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'mechanism': 0.19; 'header:User-Agent:1': 0.23; 'specify': 0.24; 'options': 0.25; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'database,': 0.30; 'with,': 0.31; 'file': 0.32; 'open': 0.33; '"the': 0.34; 'subject:the': 0.34; 'but': 0.35; 'two': 0.37; 'system,': 0.38; 'server': 0.38; 'conditions.': 0.38; 'jason': 0.38; 'to:addr:python-list': 0.38; 'environment.': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'release': 0.40; 'how': 0.40; 'read': 0.60; 'dave': 0.60; 'till': 0.61; 'no.': 0.61; 'entire': 0.61; 'taking': 0.65; 'close': 0.67; 'cpu,': 0.84; "it'd": 0.84; 'presumably': 0.84; 'received:139': 0.84; 'angel': 0.91; 'race': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Neal Becker <ndbecker2@gmail.com>
Subject Re: Concurrent writes to the same file
Date Thu, 11 Jul 2013 11:58:57 -0400
References <CANy1k1iCT3O=o6AwrpaZemzup1dQRwq-vpoperegamtB2psbcA@mail.gmail.com> <krlg5i$rqj$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host exa2-in-fw-01-epn.hns.com
User-Agent KNode/4.10.4
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4593.1373558361.3114.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1373558361 news.xs4all.nl 15877 [2001:888:2000:d::a6]:51847
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:50460

Show key headers only | 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