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


Groups > comp.lang.python > #50414

Re: Concurrent writes to the same file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.006
X-Spam-Evidence '*H*': 0.99; '*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; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 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; 'header:In-Reply-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; '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; 'till': 0.61; 'no.': 0.61; 'entire': 0.61; 'close': 0.67; 'cpu,': 0.84; "it'd": 0.84; 'presumably': 0.84; 'race': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: Concurrent writes to the same file
Date Thu, 11 Jul 2013 01:34:48 -0400
References <CANy1k1iCT3O=o6AwrpaZemzup1dQRwq-vpoperegamtB2psbcA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 174.32.174.30
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7
In-Reply-To <CANy1k1iCT3O=o6AwrpaZemzup1dQRwq-vpoperegamtB2psbcA@mail.gmail.com>
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.4566.1373520906.3114.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1373520906 news.xs4all.nl 15940 [2001:888:2000:d::a6]:53926
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:50414

Show key headers only | View raw


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?




-- 
DaveA

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


Thread

Re: Concurrent writes to the same file Dave Angel <davea@davea.name> - 2013-07-11 01:34 -0400

csiph-web