Message406504
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. |
|
Date |
User |
Action |
Args |
2021-11-17 22:58:01 | zach.ware | set | recipients:
+ zach.ware, Brian McCutchon |
2021-11-17 22:58:01 | zach.ware | set | messageid: <1637189881.29.0.534479777545.issue45833@roundup.psfhosted.org> |
2021-11-17 22:58:01 | zach.ware | link | issue45833 messages |
2021-11-17 22:58:01 | zach.ware | create | |
|