[Python-ideas] BackupFile

Kim Gräsman kim at mvps.org
Mon Jun 25 17:03:12 CEST 2012


Hi Mike,

On Mon, Jun 25, 2012 at 3:41 PM, Mike Graham <mikegraham at gmail.com> wrote:
>
> I like the basic idea, but if we do something like this, it would be
> useful to have read access to the old version of the file while you
> are writing out the new version that might become permanent.

Thanks, though this sounds like another mechanism than the one I'm
aiming for :-)

I want to replace an existing file temporarily, and then restore it no
matter what.

> If I was to implement something like this, I'd use a "right a
> temporary file then copy it overwriting the old one when I'm done"
> approach rather than a "back up the file" approach so that if the
> process dies for a reason Python can't clean up after (like due to
> SIGKILL), the half-written file doesn't remain.

This is a very valid concern -- if the process dies unexpectedly I'd
leave the file replaced and the original in some temporary directory.
Not sure if there's a way around that, probably not.

> I don't really like the name Backup but I can't think of a better name
> at the moment.

Me neither.

Thanks,
- Kim



More information about the Python-ideas mailing list