[Python-checkins] peps: PEP 446: update os.dup2()

victor.stinner python-checkins at python.org
Wed Aug 21 01:04:19 CEST 2013


http://hg.python.org/peps/rev/b72b8b295eb9
changeset:   5069:b72b8b295eb9
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Aug 21 01:04:11 2013 +0200
summary:
  PEP 446: update os.dup2()

files:
  pep-0446.txt |  28 +++-------------------------
  1 files changed, 3 insertions(+), 25 deletions(-)


diff --git a/pep-0446.txt b/pep-0446.txt
--- a/pep-0446.txt
+++ b/pep-0446.txt
@@ -472,7 +472,6 @@
  * ``io.open()``
  * ``open()``
  * ``os.dup()``
- * ``os.dup2()``
  * ``os.fdopen()``
  * ``os.open()``
  * ``os.openpty()``
@@ -513,8 +512,9 @@
   process after the ``fork()`` and before ``execv()``, so the inheritable
   flag of file descriptors is unchanged in the parent process.
 
-* ``os.dup2(fd, fd2)`` makes *fd2* inheritable if *fd2* is ``0``
-  (stdin), ``1`` (stdout) or ``2`` (stderr).
+* ``os.dup2()`` has a new optional *inheritable* parameter:
+  ``os.dup2(fd, fd2, inheritable=True)``. *fd2* is created inheritable
+  by default, but non-inheritable if *inheritable* is ``False``.
 
 Since Python should only create non-inheritable file descriptors, it is
 safe to use subprocess with the *close_fds* parameter set to ``False``.
@@ -581,28 +581,6 @@
 consensus could be reached.
 
 
-No special case for standard streams
-------------------------------------
-
-Functions handling file descriptors should not handle standard streams
-(file descriptors ``0``, ``1``, ``2``) differently.
-
-This option does not work on Windows. On Windows, calling
-``SetHandleInformation()`` to set or clear ``HANDLE_FLAG_INHERIT`` flag
-on standard streams (0, 1, 2) fails with the Windows error 87 (invalid
-argument). If ``os.dup2(fd, fd2)`` would always make *fd2*
-non-inheritable, the function would raise an exception when used to
-redirect standard streams.
-
-Another option is to add a new *inheritable* parameter to ``os.dup2()``.
-
-This PEP has a special-case for ``os.dup2()`` to not break backward
-compatibility on applications redirecting standard streams before
-calling the C function ``execv()``. Examples in the Python standard
-library: ``CGIHTTPRequestHandler.run_cgi()`` and ``pty.fork()`` use
-``os.dup2()`` to redict stdin, stdout and stderr.
-
-
 Python Issues
 =============
 

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list