Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31653
| 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 | <oscar.j.benjamin@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.020 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; "'w')": 0.09; '(without': 0.09; 'prevents': 0.09; 'subject:files': 0.09; 'suggestions:': 0.09; 'truncate': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; "'w'": 0.16; '*before*': 0.16; 'benjamin': 0.16; 'received:mail- wi0-f178.google.com': 0.16; 'truncates': 0.16; 'worst': 0.16; 'wrote:': 0.17; 'cc:2**0': 0.23; 'comment:': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'url:wiki': 0.26; 'checking': 0.27; 'prevent': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'locking': 0.29; 'url:wikipedia': 0.29; 'case,': 0.29; 'this.': 0.29; "i'm": 0.29; 'mode': 0.30; 'file': 0.32; 'received:google.com': 0.34; 'thanks': 0.34; 'open': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'test': 0.36; 'should': 0.36; 'possible': 0.37; 'october': 0.37; 'does': 0.37; 'two': 0.37; 'being': 0.37; 'why': 0.37; 'received:209': 0.37; 'far': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'shows': 0.38; 'url:en': 0.38; 'header:Received:5': 0.40; 'end': 0.40; 'think': 0.40; 'skip:u 10': 0.60; 'link': 0.60; 'different': 0.63; 'here': 0.65; 'andrea': 0.84; 'oscar': 0.84; 'try,': 0.84; 'understood.': 0.84; 'instantly': 0.93; 'processes,': 0.93 |
| 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=Z9AFcJjCZ7xuoTEyB9v9eZLbZg7NbWOQdc7Oh5PZrT8=; b=RbWQ0niU7XNqgTWbIR40YwX9RMUwp2rPLSiPlbpWmpIhPBn6QBUe/2C0HahfAHbqd8 5FoQ6/dhcXfNEZNTxL5yEklJDEBVnkA0bnCNra1NKv33JpKTydRd+fmlY5ixSHEJ83+H QsbI2JHGzrtpo520UwIlWuFwvq+Y8rMmeKY4CjWYUAm6CYOj3FTh1KYQjFY30qLTAAOC gaKkRi5jMuNmQ6sqldB95NYbOm74j34684vHphXgzVagFzCe046/Qr0cBPjNCeVoNncB 6S/bCRPikdY2BjiTWc+NQDv4nV+ea7IijzBAX39fLFrOKsAkXlxgXawk+n6raqGUquyn 3/8A== |
| MIME-Version | 1.0 |
| In-Reply-To | <CAF_E5Jbf3FagsPaMcQ11pKiPAzPSA2G-cS7r8Jemr84MaoKRyg@mail.gmail.com> |
| References | <mailman.2430.1350566044.27098.python-list@python.org> <k5p03u$3t8$2@reader1.panix.com> <mailman.2431.1350567869.27098.python-list@python.org> <k5p1rg$et4$1@reader1.panix.com> <CAF_E5Jb9javdypCvPpVGkq+zPLmt-autD=bu+Z-uDrghhGneog@mail.gmail.com> <CAHVvXxTCE8d_RoKgiT2S1XgMpUNPpd5gMHbCunicjEOOfU1GnQ@mail.gmail.com> <CAF_E5Jbf3FagsPaMcQ11pKiPAzPSA2G-cS7r8Jemr84MaoKRyg@mail.gmail.com> |
| Date | Thu, 18 Oct 2012 16:31:42 +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.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.2447.1350574309.27098.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1350574309 news.xs4all.nl 6853 [2001:888:2000:d::a6]:41267 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:31653 |
Show key headers only | View raw
On 18 October 2012 16:08, andrea crotti <andrea.crotti.0@gmail.com> wrote: > 2012/10/18 Oscar Benjamin <oscar.j.benjamin@gmail.com>: >> >> Why not come up with a test that actually shows you if it works? Here >> are two suggestions: >> >> 1) Use time.sleep() so that you know how long the lock is held for. >> 2) Write different data into the file from each process and see what >> you end up with. >> > > > Ok thanks I will try, but I thought that what I did was the worst > possible case, because I'm opening and writing on the same file from > two different processes, locking the file with LOCK_EX. > > It should not open it at all as far as I understood... I don't think you have understood. Read the link that Grant posted: http://en.wikipedia.org/wiki/File_locking#In_Unix-like_systems And my other comment: >> def write_to_file(): >> with open(FILENAME, 'w') as to_lock: > > I don't think it will work if you truncate the file like this. This > will empty the file *before* checking for the lock. Try opening the > file for reading and writing (without truncating). The lock is cooperative. It does not prevent the file from being opened or overwritten. It only prevents any other process from obtaining the lock. Here you open the file with mode 'w' which truncates the file instantly (without checking for the lock). Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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