[Python-Dev] PEP 446: Open issues/questions

Antoine Pitrou solipsis at pitrou.net
Mon Jul 29 23:49:49 CEST 2013


On Mon, 29 Jul 2013 23:42:36 +0200
Victor Stinner <victor.stinner at gmail.com> wrote:
> 
> >> So perhaps only the *original* standard streams should be left
> >> inheritable?
> 
> I plan to only change functions *creating* (and replacing) new file
> descriptors. Existing file descriptors (like 0, 1, 2) are unchanged.

You can create fds 0, 1 and 2 if they were closed before.

> > Having stdin/stdout/stderr cloexec (e.g. after a dup() to redirect to
> > a log file, a socket...) will likely break a lot of code, e.g. code
> > using os.system(), or code calling exec manually (and I'm sure there's
> > a bunch of it).
> 
> I propose to add just one special case os.dup2(fd, fd2): if fd2 < 3,
> fd2 is set to inheritable (otherwise, fd2 is set to non-inheritable).
> os.dup2() is commonly used to replace stdin, stdout and stderr between
> fork and exec. The http.server (cgi server) and pty modules use dup2()
> for example

Mmh. Doing it only in dup2() sounds like too much special casing for me.
I would prefer adding a new explicit parameter:
  os.dup2(fd, fd2, inheritable=False)

(as a bonus, it can be implemented using dup3() under (GNU/)Linux)

Regards

Antoine.


More information about the Python-Dev mailing list