Bugs item #476138, was opened at 2001-10-29 13:14 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=476138&group_id=5470 Category: Python Library Group: None >Status: Closed >Resolution: Fixed Priority: 5 Submitted By: Jeremy Hylton (jhylton) Assigned to: Tim Peters (tim_one) Summary: tempfile behavior across platforms Initial Comment: The object returned by TemporaryFile.tempfile() has a close() method. On Unix, this is a builtin file object's close method. On Windows, it is a TemporaryFileWrapper object's close method. The two have different semantics, which limits the utility of the module in code that should run on both platforms. There are two differences: - The close() method on Windows unlinks the file after closing it. The close() method on Unix does not. - Calling close() on a closed tempfile raises an exception on Windows, but has no effect on Unix. (This is a consequence of the previous difference. The second attempt to unlink the file fails.) I think the sensible fix is to catch and ignore failed unlink calls on Windows. ---------------------------------------------------------------------- >Comment By: Tim Peters (tim_one) Date: 2001-10-29 13:48 Message: Logged In: YES user_id=31435 tempfiles can now be closed any number of times on Windows, although if the unlink fails on Windows something is wrong, so I don't suppress that: Lib/tempfile.py; new revision: 1.32 Lib/test/test_tempfile.py; initial revision: 1.1 ---------------------------------------------------------------------- Comment By: Tim Peters (tim_one) Date: 2001-10-29 13:31 Message: Logged In: YES user_id=31435 Well, on Unix the file is unlinked before the tempfile *create* returns. That isn't possible on Windows. I agree a tempfile should-- like a Python file object --be closeable any number of times, although it should raise an exception if the *first* attempt to unlink it fails. ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2001-10-29 13:21 Message: Logged In: YES user_id=6380 The first difference doesn't really bother you, does it? On Unix, the file has already been unlinked when it was first created. It sounds like the real difference you're after is that the Unix version allows calling close() more than once, because open files can be closed more than once. I think this is a useful semantic to retain, and propose to fix it as you suggest. ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=476138&group_id=5470
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4