Commit a8409fb5 authored by Tim Peters's avatar Tim Peters

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.
parent 3b0b3169
...@@ -131,14 +131,16 @@ class TemporaryFileWrapper: ...@@ -131,14 +131,16 @@ class TemporaryFileWrapper:
def __init__(self, file, path): def __init__(self, file, path):
self.file = file self.file = file
self.path = path self.path = path
self.close_called = 0
def close(self): def close(self):
self.file.close() if not self.close_called:
os.unlink(self.path) self.close_called = 1
self.file.close()
os.unlink(self.path)
def __del__(self): def __del__(self):
try: self.close() self.close()
except: pass
def __getattr__(self, name): def __getattr__(self, name):
file = self.__dict__['file'] file = self.__dict__['file']
......
# SF bug #476138: tempfile behavior across platforms
# Ensure that a temp file can be closed any number of times without error.
import tempfile
f = tempfile.TemporaryFile("w+b")
f.write('abc\n')
f.close()
f.close()
f.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment