mirror of
https://github.com/python/cpython.git
synced 2024-11-28 04:15:11 +08:00
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.
This commit is contained in:
parent
e59feb5edc
commit
c57a285cb4
@ -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']
|
||||
|
10
Lib/test/test_tempfile.py
Normal file
10
Lib/test/test_tempfile.py
Normal file
@ -0,0 +1,10 @@
|
||||
# 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()
|
Loading…
Reference in New Issue
Block a user