Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.138.MISMATCH!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.049 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'true,': 0.05; 'subject:process': 0.09; 'cc:addr:python-list': 0.11; 'systems.': 0.12; 'luckily': 0.16; 'merely': 0.16; 'prevent': 0.16; 'trying': 0.19; 'file,': 0.19; 'pfxlen:0': 0.19; 'written': 0.21; 'cc:addr:python.org': 0.22; 'error': 0.23; 'certainly': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'generally': 0.29; 'unix': 0.29; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'releasing': 0.31; 'file': 0.32; 'not.': 0.33; 'maybe': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'done': 0.36; 'application': 0.37; 'two': 0.37; 'conditions.': 0.38; 'sure': 0.39; 'remove': 0.60; 'manually': 0.60; 'such': 0.63; 'become': 0.64; 'competition': 0.65; 'minutes': 0.67; 'risk': 0.72; 'recover': 0.91; 'race': 0.95 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:content-transfer-encoding; bh=uzEXbgyMvIGcyU/l+E79EmElTlOA5+etKDktEpIPAAM=; b=giKczMZJiPPI1J9G4DGz2l+IPMW6HSLmAR2sKN0FJwJnXqtB7TeOZCdN3hOVp34qZB 62wPu+eOX2cnhRypqDM1IaoHSUBwGavpAsCxuxvxt4VWJudq/LgDsNPuDsHXYzPYTdch VLu2nCJJh0usqC1Rg1ybdsDHSppz1QF4fWga18q5lNLC/gwniw1OzNRwJe5/SD6orQ3X JkMrK0G4VTTm+eGvvv+lITO4kcTs5V1RkycZc4VCOf7KqBMQza6S/S5Gwwc3m3bjOBbX jyhCXuECRVYUcYYz+BUqxK5oU+jJcSS3Ursif+6YaeOsZRv+wrj3cJAGsSKYAUlWEBQP Futg== MIME-Version: 1.0 X-Received: by 10.42.110.147 with SMTP id q19mr3662135icp.6.1382148511767; Fri, 18 Oct 2013 19:08:31 -0700 (PDT) In-Reply-To: References: Date: Fri, 18 Oct 2013 20:08:31 -0600 Subject: Re: Inter-process locking From: Jason Friedman To: Piet van Oostrum Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382148520 news.xs4all.nl 16006 [2001:888:2000:d::a6]:49256 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57085 > There is one caveat, however. If a process that has the lock crashes with= out releasing the lock, the lock file will stay around and prevent other pr= ocesses to acquire it. Then you will have to manually remove it. I generall= y prefer a solution where the pid of the locking process is written to the = lock file, so that other processes trying to acquire the lock can find out = if the process is still around and remove the lock file if not. I have seen= such solutions on Unix systems. But I am not sure if this can be done in a= platform independent way without the risk of race conditions. Maybe I have= to find out. True, luckily my application need not be that accurate. Competition for the lock will be rare. My present solution waits a few minutes for the lock to become available, and if not available after that time takes it forcefully (which lockfile handily provides). Certainly not foolproof, but we can recover merely by re-running, so if I get an error or two each year that is acceptable.