[issue45833] NamedTemporaryFile deleted before enclosing context manager exit

2021-11-22 Thread Zachary Ware
Change by Zachary Ware : -- stage: -> resolved status: pending -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue45833] NamedTemporaryFile deleted before enclosing context manager exit

2021-11-17 Thread Zachary Ware
Zachary Ware added the comment: 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`

[issue45833] NamedTemporaryFile deleted before enclosing context manager exit

2021-11-17 Thread Brian McCutchon
New submission from Brian McCutchon : Consider the following code: # Copyright 2021 Google LLC. # SPDX-License-Identifier: Apache-2.0 import contextlib import os @contextlib.contextmanager def my_tmp_file(): with tempfile.NamedTemporaryFile('w') as f: yield f