diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-10-29 21:46:08 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-10-29 21:46:08 (GMT) |
commit | c57a285cb4cd61439fd3ea804184ed8a8a1ac358 (patch) | |
tree | 5d02a253374face30c3a65c4be3bee4fd39fd2d3 /Lib/tempfile.py | |
parent | e59feb5edc40a052995ed122bf67d0a8ab7ea8c2 (diff) | |
download | cpython-c57a285cb4cd61439fd3ea804184ed8a8a1ac358.zip cpython-c57a285cb4cd61439fd3ea804184ed8a8a1ac358.tar.gz cpython-c57a285cb4cd61439fd3ea804184ed8a8a1ac358.tar.bz2 |
SF bug #476138: tempfile behavior across platforms
Ensure that a tempfile can be closed any number of times without error.
This wasn't true on Windows.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r-- | Lib/tempfile.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py index f1d53db..96245d8 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -131,14 +131,16 @@ class TemporaryFileWrapper: def __init__(self, file, path): self.file = file self.path = path + self.close_called = 0 def close(self): - self.file.close() - os.unlink(self.path) + if not self.close_called: + self.close_called = 1 + self.file.close() + os.unlink(self.path) def __del__(self): - try: self.close() - except: pass + self.close() def __getattr__(self, name): file = self.__dict__['file'] |