Idiom for shelling out to $EDITOR/$PAGER?

Devin Jeanpierre jeanpierreda at gmail.com
Fri Dec 23 16:01:17 EST 2011


> 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 <cs at zip.com.au> wrote:
> On 23Dec2011 02:21, Devin Jeanpierre <jeanpierreda at gmail.com> 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 <cs at zip.com.au> 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.
>        - Death, 'Reaper Man' (Pratchett)



More information about the Python-list mailing list