[issue44013] tempfile.TemporaryFile: name of file descriptor cannot be reused in consecutive initialization

Xiang Zhong report at bugs.python.org
Mon Jun 7 18:11:27 EDT 2021


Xiang Zhong <zhongxiang117 at gmail.com> added the comment:

Dear Mr. Jollans,

Thanks for your additions, I think I know well about the SHELL programming language, now, every thing about the low-level file descriptors is linked together. I guess now I completely know your writing, thanks again for your detail explanations!

The potential “bug” of your consideration is the post operation caused by OS.close() in the delay/conflict of tempfile.Temporary(), as a result, fd does not know whether its linked file descriptor is valid or not due to “with” method.

However, if you have a look on “test_4” in attached “xtempfile.py”, you will see that in the first fd generated by tempfile.Temporary(), it is assumed to be handled by the first “with”, no more other operations are executed. Even after first “with” it becomes invalid, there are no further executions performed.

On the second fd returned by tempfile.TemporaryFile(), it should be a valid file descriptor no matter how the first one is dealt with. From the coding perspective, these two variables are just “happen to” be the same chars.

Besides, from my testing, changing any one of them to the different variable name, then the problem is gone. Furthermore, if you have a look on “test_3”, “test_5” and “test_6” (xtempfile.py), especially on “test_5”, they all prove that it should be a bug.

To go deeper, I attached another test file “new-xtempfile.py”, on “test_11”, you will see that it should have some problems on "__del__" method if its linking file descriptor is closed by os.close().

They two may or may not be the same problem.


Thanks again for your illustration of “fd.fileno()” and “fd.name”.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44013>
_______________________________________


More information about the Python-bugs-list mailing list