[Python-checkins] cpython (2.7): Issue #18763: subprocess: The file descriptors are now closed after calling the

charles-francois.natali python-checkins at python.org
Sun Aug 25 18:29:42 CEST 2013


http://hg.python.org/cpython/rev/f2b023135b1b
changeset:   85390:f2b023135b1b
branch:      2.7
parent:      85367:23181bf411a1
user:        Charles-François Natali <cf.natali at gmail.com>
date:        Sun Aug 25 18:22:49 2013 +0200
summary:
  Issue #18763: subprocess: The file descriptors are now closed after calling the
preexec_fn callback, which may open file descriptors.

files:
  Lib/subprocess.py |  9 +++++----
  1 files changed, 5 insertions(+), 4 deletions(-)


diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1247,16 +1247,17 @@
                                     os.close(fd)
                                     closed.add(fd)
 
-                            # Close all other fds, if asked for
-                            if close_fds:
-                                self._close_fds(but=errpipe_write)
-
                             if cwd is not None:
                                 os.chdir(cwd)
 
                             if preexec_fn:
                                 preexec_fn()
 
+                            # Close all other fds, if asked for - after
+                            # preexec_fn(), which may open FDs.
+                            if close_fds:
+                                self._close_fds(but=errpipe_write)
+
                             if env is None:
                                 os.execvp(executable, args)
                             else:

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


More information about the Python-checkins mailing list