STINNER Victor <vstin...@python.org> added the comment:

> 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 !
https://lwn.net/Articles/789023/
... 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38061>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to