Skip to content

Commit ee22809

Browse files
committed
For Windows, there can't be open file handles when calling try_delete(), so make sure the temp file handle is closed.
1 parent cdc942d commit ee22809

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

tools/tempfiles.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ def get(self, suffix):
4545
return named_file
4646

4747
def get_file(self, suffix):
48-
"""Returns an object representing a temp file, that has convenient pythonesque semantics for being
49-
used via a construct 'with TempFiles.get_file(..) as filename:'. The file will be deleted immediately
50-
once the with block is exited."""
48+
"""Returns an object representing a RAII-like access to a temp file, that has convenient pythonesque
49+
semantics for being used via a construct 'with TempFiles.get_file(..) as filename:'. The file will be
50+
deleted immediately once the 'with' block is exited."""
5151
class TempFileObject:
5252
def __enter__(self_):
5353
self_.file = tempfile.NamedTemporaryFile(dir=self.tmp, suffix=suffix, delete=False)
54+
self_.file.close() # NamedTemporaryFile passes out open file handles, but callers prefer filenames (and open their own handles manually if needed)
5455
return self_.file.name
5556

5657
def __exit__(self_, type, value, traceback):

0 commit comments

Comments
 (0)