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.

Author zach.ware
Recipients Brian McCutchon, zach.ware
Date 2021-11-17.22:58:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1637189881.29.0.534479777545.issue45833@roundup.psfhosted.org>
In-reply-to
Content
It's a bit convoluted, but the file is actually deleted before the `os.stat` call.  Because there are no references to anything but the `name` (which is just a string), the `_GeneratorContextManager` (result of `my_tmp_file`) and the `_TemporaryFileWrapper` (result of `my_tmp_file().__enter__()`) are both destroyed.  Because `NamedTemporaryFile` is called with `delete=True` (default), the `_TemporaryFileWrapper` has a `_closer` attribute which is a `_TemporaryFileCloser`, which calls `self.close()` in `__del__`, which deletes the file.

If a reference to the result of `my_tmp_file()` is saved anywhere along the way, none of the objects are destroyed and the file still exists.  This also wouldn't happen in an implementation without reference counting.
History
Date User Action Args
2021-11-17 22:58:01zach.waresetrecipients: + zach.ware, Brian McCutchon
2021-11-17 22:58:01zach.waresetmessageid: <1637189881.29.0.534479777545.issue45833@roundup.psfhosted.org>
2021-11-17 22:58:01zach.warelinkissue45833 messages
2021-11-17 22:58:01zach.warecreate