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


Groups > comp.lang.python > #88393

Re: Lockfile hanling

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <mmr15@case.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*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; '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; '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; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:org': 0.36; 'should': 0.36; 'application': 0.37; 'received:209': 0.37; 'received:10': 0.37; 'handle': 0.38; 'how': 0.40; 'ensure': 0.60; 'url:5': 0.61; 'to:addr:gmail.com': 0.65; 'between': 0.67; 'datas': 0.84; 'polling': 0.84
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=pIwUijE6aZTFeJuBxfuWxTDDJM+Pi8H+PaB1SUBtz5c=; b=GCNBPbmtOWoCRkGxkgYRPueVqz+daWokfsHqmCBF1e2Uh5AqiChkjDe3Yt/AxRoB6m 03Of6jH3wj0HXTDhQinvsEx07jgiXXeWiFmu+EVhCNImitwV4duV7XedCOER7P1k01/P xSgyFXWvpBW5ZA1QxfWZpHM7ISxpRZPHxlXuB6Pto1pXksak9JLurEYd6jZHLLeB1En7 M3hT8hxvyrPpnhGT4THhB2GYwK8rIEvLGcDrIBNw00E2axnfQXdob3vZbV7nNII9IpF0 yeTLOfCKsSkpf0/lGammnyqIkGDUHLA0r8URswvE2EINcW7epq0pD1+MKGYVy4k3/FFm l2Yg==
X-Gm-Message-State ALoCoQkrDFEx90es/Y7+ruMMQ96jbBn0e8aWvhwE4JOcRnhLEInfabcLpRcKDBzqPK6rCR2mybIcAqFhre0BG0knO7X1wjxR5Agzu2RLzxbQJPzMbLeY6uF/jb8dZdB6S8Rh8Qgn9ja1
X-Received by 10.55.42.88 with SMTP id q85mr79301495qkh.65.1427817008261; Tue, 31 Mar 2015 08:50:08 -0700 (PDT)
X-Received by 10.55.42.88 with SMTP id q85mr79301479qkh.65.1427817008183; Tue, 31 Mar 2015 08:50:08 -0700 (PDT)
From Matthew Ruffalo <mmr15@case.edu>
X-Google-Original-From Matthew Ruffalo <matthew.ruffalo@case.edu>
Date Tue, 31 Mar 2015 11:50:06 -0400
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
To Ervin Hegedüs <airween@gmail.com>
CC python-list@python.org
Subject Re: Lockfile hanling
References <20150331145012.GA4460@arxnet.hu>
In-Reply-To <20150331145012.GA4460@arxnet.hu>
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Junkmail-Whitelist YES (by domain whitelist at mpv2.tis.cwru.edu)
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.380.1427817413.10327.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1427817413 news.xs4all.nl 2944 [2001:888:2000:d::a6]:36128
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:88393

Show key headers only | View raw


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...

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


Thread

Re: Lockfile hanling Matthew Ruffalo <mmr15@case.edu> - 2015-03-31 11:50 -0400

csiph-web