From: Charles-François Natali Date: Sun, 25 Aug 2013 16:22:49 +0000 (+0200) Subject: Issue #18763: subprocess: The file descriptors are now closed after calling the X-Git-Tag: v2.7.6rc1~194^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c5331447561250bc1172dd4310351cf0707f056;p=thirdparty%2FPython%2Fcpython.git Issue #18763: subprocess: The file descriptors are now closed after calling the preexec_fn callback, which may open file descriptors. --- diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 50bec291c5a5..814cfbe60f19 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1247,16 +1247,17 @@ class Popen(object): 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: