This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Documentation says destuction of TemporaryDirectory object will also delete it, but it does not.
Type: behavior Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ammar2, iarp
Priority: normal Keywords:

Created on 2019-09-27 19:45 by iarp, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg353393 - (view) Author: Ian (iarp) Date: 2019-09-27 19:45
The documentation found here https://docs.python.org/3.7/library/tempfile.html#tempfile.TemporaryDirectory states the following

"On completion of the context or destruction of the temporary directory object the newly created temporary directory and all its contents are removed from the filesystem."

However calling del on the object does not call the cleanup method.

t = tempfile.TemporaryDirectory()
del t

I'm not sure if that is incorrect documentation or my own misunderstanding of what you call destruction. I tested adding my own def __del__(): self.cleanup() which worked as I expected.
msg353394 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2019-09-27 19:51
Hmm, I can't recreate this locally:

>>> import tempfile
>>> import os
>>> t = tempfile.TemporaryDirectory()
>>> temp_dir = t.name
>>> os.path.exists(temp_dir)
True
>>> del t
>>> os.path.exists(temp_dir)
False

What version of Python are you using?
msg353425 - (view) Author: Ian (iarp) Date: 2019-09-27 22:57
I'm sorry, I should've thought to check my python version. I was on 3.6.3 which it would not be deleted, updated to 3.6.8 and it works as intended.
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82481
2019-09-27 22:57:01iarpsetstatus: open -> closed
versions: - Python 3.7
messages: + msg353425

resolution: not a bug
stage: resolved
2019-09-27 19:51:07ammar2setnosy: + ammar2
messages: + msg353394
2019-09-27 19:45:13iarpcreate