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 vstinner
Recipients bup, gregory.p.smith, iritkatriel, neologix, pitrou, serhiy.storchaka, sstewartgallus, vstinner
Date 2021-09-20.08:29:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632126562.8.0.29165971551.issue21627@roundup.psfhosted.org>
In-reply-to
Content
I close the issue as "not a bug". If you disagree, please comment the issue :-)

Steven Stewart-Gallus:
> In the code FD_DIR is "/proc/self/fd" on Linux. I'm not sure this code
> is correct. This seems as if it would have the same problems as
> iterating over a list and modifying it at the same time.

I don't understand the initial issue. What makes you think that the current code is not reliable? Python is using this code for years, and so far, nobody reported any crash on this code.

You didn't report a crash, you only wrote that you suspect that there is a bug. Can you prove that the current Python code is wrong? Did you look at the implementation of readdir() in the Linux glibc for example?

About close() vs marking file descriptor non inheritable, I'm not convinced that marking file descriptors is faster or more reliable. On many operating systems, _Py_set_inheritable() requires 2 syscalls (get flags, set flags), whereas close() is a single syscall: calling close() is faster.

---

Python now has a _Py_closerange() function which supports:

* Linux closerange() syscall, calling the glibc closerange() function
* FreeBSD closefrom() function
* Solaris fdwalk() function

On Linux, _posixsubprocess still iterates /proc/self/pid/ if this directory can be opened, even if the closerange() function is available. I'm not sure which option is the safest or the fastest. 

By the way, Steven Stewart-Gallus did mention his operating system.
History
Date User Action Args
2021-09-20 08:29:22vstinnersetrecipients: + vstinner, gregory.p.smith, pitrou, neologix, serhiy.storchaka, sstewartgallus, bup, iritkatriel
2021-09-20 08:29:22vstinnersetmessageid: <1632126562.8.0.29165971551.issue21627@roundup.psfhosted.org>
2021-09-20 08:29:22vstinnerlinkissue21627 messages
2021-09-20 08:29:22vstinnercreate