This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients r.david.murray
Date 2012-04-06.02:00:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1333677629.14.0.589008132421.issue14514@psf.upfronthosting.co.za>
In-reply-to
Content
A common pattern (especially in writing tests) is to create a named temporary file, operate on it with tools that take the filename, and then delete the file.  This pattern would be facilitated by a version of NamedTemporaryFile that deleted the named file at the end of the context, but allowed the file to continue to exist when closed.  This latter requirement arises because the file cannot be opened a second time on Windows, and so needs to be closed before other operations that open it can be performed in order for the code to work cross platform.

It's tempting just to change delete=True to mean delete on exit (not close) if and only if NamedTemporaryFile is being used as a context manager, but there might be backward compatibility issues with that.  It might be acceptable as a feature change, though, since the likelyhood of someone closing such a tempfile inside the context and then depending on it *not* existing between then and the end of the context seems low.

If that it deemed unacceptable, this could be implemented as a new flag on NamedTemporaryFile, or by changing the delete flag to take additional values (True/False == current behavior, but add delete='onclose', delete='onexit', delete='no', and document True/False as deprecated.)
History
Date User Action Args
2012-04-06 02:00:29r.david.murraysetrecipients: + r.david.murray
2012-04-06 02:00:29r.david.murraysetmessageid: <1333677629.14.0.589008132421.issue14514@psf.upfronthosting.co.za>
2012-04-06 02:00:28r.david.murraylinkissue14514 messages
2012-04-06 02:00:28r.david.murraycreate