diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-02-12 22:35:30 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-02-12 22:35:30 (GMT) |
commit | f6b361ec1a10b93ff8b927b400ca1777429bb23a (patch) | |
tree | 19679051591f3dda745d47ebca1d0d95e4bd1e6c /Lib/tempfile.py | |
parent | e4ad8aacd1b10ef14d2a6d44c4c1ebd283ede6bb (diff) | |
download | cpython-f6b361ec1a10b93ff8b927b400ca1777429bb23a.zip cpython-f6b361ec1a10b93ff8b927b400ca1777429bb23a.tar.gz cpython-f6b361ec1a10b93ff8b927b400ca1777429bb23a.tar.bz2 |
Issue #16800: tempfile.gettempdir() no longer left temporary files when
the disk is full. Original patch by Amir Szekely.
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: |