From 47f14bade8f1d9517fca4bcddb1162f4e9845e12 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 3 Jan 2011 23:42:01 +0000 Subject: Un-complicate some code --- Lib/subprocess.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 7d3f77f..5c5e9f2 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1092,15 +1092,9 @@ class Popen(object): errread, errwrite) - def _close_fds(self, but): - os.closerange(3, but) - os.closerange(but + 1, MAXFD) - - - def _close_all_but_a_sorted_few_fds(self, fds_to_keep): - # precondition: fds_to_keep must be sorted and unique + def _close_fds(self, fds_to_keep): start_fd = 3 - for fd in fds_to_keep: + for fd in sorted(fds_to_keep): if fd >= start_fd: os.closerange(start_fd, fd) start_fd = fd + 1 @@ -1216,13 +1210,9 @@ class Popen(object): # Close all other fds, if asked for if close_fds: - if pass_fds: - fds_to_keep = set(pass_fds) - fds_to_keep.add(errpipe_write) - self._close_all_but_a_sorted_few_fds( - sorted(fds_to_keep)) - else: - self._close_fds(but=errpipe_write) + fds_to_keep = set(pass_fds) + fds_to_keep.add(errpipe_write) + self._close_fds(fds_to_keep) if cwd is not None: -- cgit v0.12