monkeypatching NamedTemporaryFile

Jason Lunz lunz at falooley.org
Sat May 27 11:17:53 EDT 2006


craighse888 at googlemail.com said:
> Maybe that should be the default behaviour.  Presumably the file has
> been deleted by some other process?

The use case is that a NamedTemporaryFile was used to securely create
and populate a file, which is then atomically (on posix) os.rename()d to
its final location.

If any error occurs prior to the rename, NamedTemporaryFile takes care
of deleting the tempfile on the error path. But in the success case,
NamedTemporaryFile causes an unsightly "ignored exception" message on
stderr when it fails to unlink the now-nonexistent tempfile.

Jason




More information about the Python-list mailing list