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


Groups > comp.lang.python > #88394

Re: Lockfile hanling

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <airween@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.028
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'python,': 0.02; 'modify': 0.07; 'app,': 0.09; 'cc:addr:python-list': 0.11; 'thread': 0.14; 'exclusion': 0.16; 'issue?': 0.16; 'threads,': 0.16; 'threads.': 0.16; 'prevent': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'app': 0.19; 'file,': 0.19; 'written': 0.21; 'python?': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; '31,': 0.24; 'bytes': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'strongly': 0.30; "i'm": 0.30; 'file': 0.32; 'this.': 0.32; 'probably': 0.32; 'another': 0.32; 'url:python': 0.33; 'running': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'next': 0.36; 'url:org': 0.36; 'should': 0.36; 'application': 0.37; 'handle': 0.38; 'how': 0.40; 'ensure': 0.60; 'hope': 0.61; 'url:5': 0.61; 'from:charset:utf-8': 0.61; 'content- disposition:inline': 0.62; 'between': 0.67; 'mar': 0.68; '2015': 0.84; 'datas': 0.84; 'matthew,': 0.84; 'polling': 0.84; 'received:86': 0.91; 'received:hu': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=5+wEdK7PPTFZCMM7igcR2PSE8rxroPXuJPR7CQUg304=; b=mSNn3v/N7kACOazvZzl3ukiX32P8KOcrUQrhSJHJMZjEiFBi1xrGQOrpht8q/uASPK 3IemH9g2eUusTFvi6t1+T+GstuiiLfrxwTFfHwmumNF3nNyvIvCZ5L6I9J08RBtQDO4y V3sZv7mS0PRqUJLLVMQsWuJOlEdQuYJwWFYhxvC40OhHyncNTSXUV0tYDF+KtRfh9P2u 6ZLqa6J8Gaa2R+829rJROmxIdAOTYAvYi4IvymwtyEur02FcB9dMMrQ+HhfikB+2IDH5 3m7Kuk6v/UojU4dIooZKcAnFeSwQee7G0xxygGs+sIHnuET8wtQoEgrlBPBd1eG1E/bJ 0NNA==
X-Received by 10.181.29.170 with SMTP id jx10mr6651389wid.29.1427817453392; Tue, 31 Mar 2015 08:57:33 -0700 (PDT)
Date Tue, 31 Mar 2015 17:58:09 +0200
From Ervin Hegedüs <airween@gmail.com>
To Matthew Ruffalo <mmr15@case.edu>
Cc python-list@python.org
Subject Re: Lockfile hanling
References <20150331145012.GA4460@arxnet.hu> <551AC22E.40209@case.edu>
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Disposition inline
Content-Transfer-Encoding 8bit
In-Reply-To <551AC22E.40209@case.edu>
User-Agent Mutt/1.5.21 (2010-09-15)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.381.1427817460.10327.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1427817460 news.xs4all.nl 2963 [2001:888:2000:d::a6]:37073
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:88394

Show key headers only | View raw


Hi Matthew,

On Tue, Mar 31, 2015 at 11:50:06AM -0400, Matthew Ruffalo wrote:
> On 2015-03-31 10:50, Ervin Hegedüs wrote:
> > there is an app, written in Python, which stores few bytes of
> > datas in a single file. The application uses threads. Every
> > thread can modify the file, but only one at a time. I'm using a
> > lock file to prevent the multiple access.
> >
> > ...
> >
> > How can I prevent or avoid this issue? What's the correct way to
> > handle the lockfile in Python?
> 
> Hi Ervin-
> 
> If only one instance of the app is running at a given time, and you only
> need to ensure mutual exclusion between its threads, you should probably
> not use a lock *file* for this. I would strongly recommend that you use
> a threading.Lock as per
> https://docs.python.org/2.5/lib/module-threading.html instead of a lock
> file. This will also allow you to avoid a 0.2-second polling loop; a
> call to threading.Lock.acquire() will block until it is released by
> another thread.
> 
> MMR...

thanks, I hope in the next version I can try this :)


a.

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


Thread

Re: Lockfile hanling Ervin Hegedüs <airween@gmail.com> - 2015-03-31 17:58 +0200

csiph-web