Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:209.85.223': 0.03; "'w')": 0.09; 'subject:files': 0.09; 'useful,': 0.13; 'to:name:python-list': 0.15; '(should': 0.16; 'happily': 0.16; 'trying': 0.21; 'this:': 0.23; 'somewhere': 0.24; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; "i'm": 0.29; 'function': 0.30; 'file': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'open': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'received:209': 0.37; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'glad': 0.86 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=mwBTKQpBLL/DkWIZ9FuoaHsk+CRItl4qsxyRapuSX/w=; b=aFytxw+L1BwwU54e5M/Kv4sGqD6NO6x5tYHbzSgQd+PsBjJcaaW+G68zhfDH3Fwdfl 490POtcLP5VUPmBsk09u6NEpnBFu+Se09ugbbjfNYZT4o9EuZsH/H0YgcCCleYhnrli3 5ee3dPP5xHbqiwhgwyZnFUfhVA2tiWFjwBlLSHHC4/HLUBDbi2ibhKkpm6UY01jBll1X +49hb5GapflaVLEeKS9t8BlAlHPtV8H+jPncEZeFSkhHuZN2dt3qegDmsY33R9zfiCPj 2htdwmPWq4Awn7EZPmazvu9QT+pnZgihJWJ6UKJ4DxFmTQT0vwDJnxROjsvA9OMxVWXy C+IA== MIME-Version: 1.0 Date: Thu, 18 Oct 2012 14:14:02 +0100 Subject: locking files on Linux From: andrea crotti To: python-list Content-Type: text/plain; charset=ISO-8859-1 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: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350566044 news.xs4all.nl 6954 [2001:888:2000:d::a6]:52044 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31633 I'm trying to understand how I can lock a file while writing on it, because I might have multiple processes working on it at the same time. I found the fcntl.lockf function but if I do this: In [109]: locked = open('locked.txt', 'w') In [110]: fcntl.lockf(locked, fcntl.LOCK_EX) I can happily open the file with vim from somewhere and write on it, so it doesn't seem to be very useful, or am I missing something? I can otherwise use the classic ".lock" file when working on it, but I would be glad to see a smarter solution (should only work on Linux)..