Issue #18763: subprocess: The file descriptors are now closed after calling the

preexec_fn callback, which may open file descriptors.
parent 59a06f50
...@@ -1247,16 +1247,17 @@ class Popen(object): ...@@ -1247,16 +1247,17 @@ class Popen(object):
os.close(fd) os.close(fd)
closed.add(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: if cwd is not None:
os.chdir(cwd) os.chdir(cwd)
if preexec_fn: if preexec_fn:
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: if env is None:
os.execvp(executable, args) os.execvp(executable, args)
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment