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 koobs, vstinner
Date 2019-09-09.13:36:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> That's very unlikely to happen. I believe it was added as an opt-in feature for some linux compatibility situations. The correct solution is to use closefrom(2), as it is the optimal current solution, and in our case, safe to use.

If you have like 50k open file descriptors and want to pass fd 50000 to a child process using Popen(pass_fds={50000}), you will have to call close() 49 997 times: close(3)..close(49999), then closefrom(50001).

For the pass_fds case, being able to enumerate open file descriptors (ex: fdescfs) is more efficient than closefrom().

Well, the best would be a system call "close all file descriptors except of <list of fds>", but it's not available yet. Or maybe at least having a system like close_range(a, b).

In May 2019, the close_range() syscall was in the Linux kernel !
... but it seems like the feature was not accepted yet.

I'm disappointed that posix_spawn() doesn't implement a feature like Python subprocess close_fds=True.
Date User Action Args
2019-09-09 13:36:56vstinnersetrecipients: + vstinner, koobs
2019-09-09 13:36:56vstinnersetmessageid: <>
2019-09-09 13:36:56vstinnerlinkissue38061 messages
2019-09-09 13:36:56vstinnercreate