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


Groups > comp.lang.python > #31638

Re: locking files on Linux

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '(even': 0.05; 'modify': 0.05; 'filesystem': 0.09; 'historically': 0.09; 'sqlite': 0.09; 'subject:files': 0.09; 'cc:addr:python-list': 0.10; 'anyway': 0.11; 'ignore': 0.13; 'bounds': 0.16; 'fcntl': 0.16; 'posted.': 0.16; 'titled': 0.16; 'too).': 0.16; 'url:documentation': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'received:74.125.82.174': 0.23; 'cc:2**0': 0.23; 'work.': 0.23; 'linux': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'url:wiki': 0.26; 'guess': 0.27; 'message-id:@mail.gmail.com': 0.27; 'locking': 0.29; 'locks': 0.29; 'url:wikipedia': 0.29; 'url:mailman': 0.29; 'probably': 0.29; "i'm": 0.29; 'maybe': 0.29; 'knows': 0.30; 'url:2012': 0.30; 'point': 0.31; 'url:python': 0.32; 'file': 0.32; 'not.': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'received:74.125.82': 0.33; 'received:google.com': 0.34; 'but': 0.36; 'received:74.125': 0.36; 'url:org': 0.36; 'level.': 0.36; "i'll": 0.36; 'should': 0.36; 'problems': 0.36; 'october': 0.37; 'does': 0.37; 'uses': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'url:en': 0.38; 'application': 0.40; 'header:Received:5': 0.40; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'most': 0.61; 'you.': 0.61; "you've": 0.61; 'worth': 0.63; 'different': 0.63; 'sit': 0.65; 'afraid': 0.66; 'attention': 0.75; 'andrea': 0.84; 'oscar': 0.84; 'edwards': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=IgizLHVLBmIKqoRmYdGniojJkAiJncdzEvsh4AVvoPo=; b=FRH4U4ncSd8lEKApRgot0orcgfqbWBJxpevYAtqRZsaIp530U/9/3H8ROozTrJoD9i ccAQ6a7jIwMGquDCxxLmKLaLxQDgh2+mjrwnR/P+8Fpce3vdWUUyJu+PADjYBmAMQ5F6 x/yZIHXewxVhNihpmfZpMg3m9uZdLofcyu019CG3V1lxQPHForKWu/sd8JX5Rv02sntE dNHsV9Ls32ADuerALnRVZY3C2s4JdGklvlrowYlDKNlSDwNR6h2c8sUUROyKh/eo1v2c 0uOyT3cF1U9Qh837hzp9Ga0gvAoCOV1F+bl++SIc5RoKb0xZvJdX16pMQlRI+8FeW7bJ u/PQ==
MIME-Version 1.0
In-Reply-To <CAF_E5Jbng4f=23NiVBvod99G8c=saFY+q2cPfR24KHLim1qaew@mail.gmail.com>
References <mailman.2430.1350566044.27098.python-list@python.org> <k5p03u$3t8$2@reader1.panix.com> <CAF_E5Jbng4f=23NiVBvod99G8c=saFY+q2cPfR24KHLim1qaew@mail.gmail.com>
Date Thu, 18 Oct 2012 14:58:48 +0100
Subject Re: locking files on Linux
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
To andrea crotti <andrea.crotti.0@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list <python-list@python.org>
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.2432.1350568730.27098.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350568730 news.xs4all.nl 6904 [2001:888:2000:d::a6]:41037
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31638

Show key headers only | View raw


On 18 October 2012 14:44, andrea crotti <andrea.crotti.0@gmail.com> wrote:
> 2012/10/18 Grant Edwards <invalid@invalid.invalid>:
>> On 2012-10-18, andrea crotti <andrea.crotti.0@gmail.com> wrote:
>>
>>
>> File locks under Unix have historically been "advisory".  That means
>> that programs have to _choose_ to pay attention to them.  Most
>> programs do not.
>>
>> Linux does support mandatory locking, but it's rarely used and must be
>> manually enabled at the filesystem level. It's probably worth noting
>> that in the Linux kernel docs, the document on mandatory file locking
>> begins with a section titled "Why you should avoid mandatory locking".
>>
>> http://en.wikipedia.org/wiki/File_locking#In_Unix-like_systems
>> http://kernel.org/doc/Documentation/filesystems/locks.txt
>> http://kernel.org/doc/Documentation/filesystems/mandatory-locking.txt
>> http://www.thegeekstuff.com/2012/04/linux-file-locking-types/
>> http://www.hackinglinuxexposed.com/articles/20030623.html
>>
>> --
>> Grant Edwards               grant.b.edwards        Yow! Your CHEEKS sit like
>>                                   at               twin NECTARINES above
>>                               gmail.com            a MOUTH that knows no
>>                                                    BOUNDS --
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
> Uhh I see thanks, I guess I'll use the good-old .lock file (even if it
> might have some problems too).

I think you've misunderstood what Grant meant.

>
> Anyway I'm only afraid that my same application could modify the
> files, so maybe I can instruct it to check if the file is locked.

In that case fcntl will work for you. The point is that fcntl only
locks the file if all of the applications accessing the file use
fcntl. Any other application such as vim can simply ignore the fcntl
lock. Have a read of the links that Grant posted.

Did you try writing twice from the same application that uses fcntl?

> Or maybe using sqlite would work even if writing from different
> processes?

That would also work.


Oscar

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


Thread

locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-18 14:14 +0100
  Re: locking files on Linux Grant Edwards <invalid@invalid.invalid> - 2012-10-18 13:27 +0000
    Re: locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-18 14:44 +0100
      Re: locking files on Linux Grant Edwards <invalid@invalid.invalid> - 2012-10-18 13:57 +0000
        Re: locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-18 15:49 +0100
        Re: locking files on Linux Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-18 16:04 +0100
        Re: locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-18 16:08 +0100
        Re: locking files on Linux Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-18 16:31 +0100
        Re: locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-19 13:15 +0100
      Re: locking files on Linux Nobody <nobody@nowhere.com> - 2012-10-19 15:36 +0100
    Re: locking files on Linux Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-18 14:58 +0100

csiph-web