diff options
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r-- | Lib/tempfile.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py index ae35314..0dbd889 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -175,11 +175,14 @@ def _get_default_tempdir(): filename = _os.path.join(dir, name) try: fd = _os.open(filename, _bin_openflags, 0o600) - fp = _io.open(fd, 'wb') - fp.write(b'blat') - fp.close() - _os.unlink(filename) - del fp, fd + try: + try: + fp = _io.open(fd, 'wb', buffering=0, closefd=False) + fp.write(b'blat') + finally: + _os.close(fd) + finally: + _os.unlink(filename) return dir except (OSError, IOError) as e: if e.args[0] != _errno.EEXIST: |