Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-transit.tcx.org.uk!rt.uk.eu.org!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.119 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.76; '*S*': 0.00; 'option,': 0.07; 'context.': 0.09; 'statement.': 0.09; 'tempfile': 0.09; 'beam': 0.16; 'gradually': 0.16; '\xc2\xa0-': 0.16; 'cc:addr:python-list': 0.16; 'linux': 0.17; 'wrote:': 0.18; 'file,': 0.19; 'cheers,': 0.20; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'figure': 0.23; 'locking': 0.23; 'mode': 0.25; 'windows': 0.26; 'message- id:@mail.gmail.com': 0.28; 'anyway.': 0.29; 'exit': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'closing': 0.30; 'least': 0.30; '(as': 0.31; 'subject:?': 0.31; "isn't": 0.33; "won't": 0.33; 'received:209.85.160': 0.33; 'fri,': 0.34; 'read,': 0.34; 'received:209.85.160.46': 0.35; 'received:mail- pw0-f46.google.com': 0.35; 'file': 0.36; 'cc:2**1': 0.36; 'but': 0.37; 'received:google.com': 0.37; "there's": 0.37; 'open': 0.38; 'hold': 0.38; 'received:209.85': 0.38; 'useful': 0.38; 'being': 0.39; "couldn't": 0.39; 'received:209': 0.40; '2011': 0.61; 'your': 0.61; 'opened': 0.64; '"what': 0.67; 'cam': 0.67; 'yeah.': 0.67; 'cameron': 0.73; 'hate': 0.73; 'race': 0.77; 'disastrous': 0.84; 'it"': 0.84; 'rebate': 0.84; 'up;': 0.84; 'contents,': 0.91; 'death,': 0.93; 'subject: $': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=pN9YcscUEDnx24WIX+lIKAWJnBOVUBk7FLEdYCUh7OI=; b=jCRkSymtGyP+a2wKNC5S+QreLaTazEjC6jIVfJskQeiMB/h83J9ycBjhgCTPw/JySw Mxeo9vZX/i3lnXGHA6/Ky7LFDjM26k51HXJZn4eX1fnstsl7zt6OMQd4pwRjpOuKoY7P LAryTLfWyJZGhctvvU1fQU9zWTAxNwaMEyP/I= MIME-Version: 1.0 In-Reply-To: <20111223194753.GA23781@cskk.homeip.net> References: <20111223194753.GA23781@cskk.homeip.net> From: Devin Jeanpierre Date: Fri, 23 Dec 2011 16:01:17 -0500 Subject: Re: Idiom for shelling out to $EDITOR/$PAGER? To: Cameron Simpson Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324674121 news.xs4all.nl 6943 [2001:888:2000:d::a6]:34881 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17825 > Windows may hate you for this with its locking behaviour for open files, > but it will work for UNIX. Windows won't let you open the file while NamedTemporaryFile has a hold on it, yeah. Your point is legitimate anyway. Even so, there's still the race conditions for "what if the tempfile is moved before the editor can get to it" and "what if the tempfile is moved after the editor can get to it but before I can open it again". -- Devin On Fri, Dec 23, 2011 at 2:47 PM, Cameron Simpson wrote: > On 23Dec2011 02:21, Devin Jeanpierre wrote: > | > Anyway, look it up; it has an autodelete mode etc. > | > | The autodelete isn't useful in this context. The file needs to be > | closed and then reopened again; with the autodelete option, the > | closing would delete the file, preventing it from being opened by the > | text editor or reopened to check contents. > | > | (As far as I know, the race condition inherent in this is unavoidable. > | At least on windows, but I couldn't figure out any other way on Linux > | either.) > > You can fire off the editor from inside the with statement. > Write contents, flush, edit, open T.name for read, read, close, exit > with statement. > > Windows may hate you for this with its locking behaviour for open files, > but it will work for UNIX. > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > The elliptical cam has gradually slid up the beam shaft and caught on the > flange rebate dislodging the gripley, with disastrous results. > =C2=A0 =C2=A0 =C2=A0 =C2=A0- Death, 'Reaper Man' (Pratchett)