diff -r bc88690df059 Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py Tue Jan 29 13:35:00 2013 +0100 +++ b/Lib/multiprocessing/connection.py Tue Jan 29 14:00:58 2013 +0100 @@ -496,13 +496,13 @@ if sys.platform != 'win32': Returns pair of connection objects at either end of a pipe ''' if duplex: - s1, s2 = socket.socketpair() + s1, s2 = socket.socketpair(cloexec=True) s1.setblocking(True) s2.setblocking(True) c1 = Connection(s1.detach()) c2 = Connection(s2.detach()) else: - fd1, fd2 = os.pipe() + fd1, fd2 = os.pipe(cloexec=True) c1 = Connection(fd1, writable=False) c2 = Connection(fd2, readable=False) @@ -559,7 +559,7 @@ class SocketListener(object): Representation of a socket which is bound to an address and listening ''' def __init__(self, address, family, backlog=1): - self._socket = socket.socket(getattr(socket, family)) + self._socket = socket.socket(getattr(socket, family), cloexec=True) try: # SO_REUSEADDR has different semantics on Windows (issue #2550). if os.name == 'posix': @@ -598,7 +598,7 @@ def SocketClient(address): Return a connection object connected to the socket given by `address` ''' family = address_type(address) - with socket.socket( getattr(socket, family) ) as s: + with socket.socket( getattr(socket, family) , cloexec=True) as s: s.setblocking(True) s.connect(address) return Connection(s.detach()) diff -r bc88690df059 Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py Tue Jan 29 13:35:00 2013 +0100 +++ b/Lib/multiprocessing/forking.py Tue Jan 29 14:00:58 2013 +0100 @@ -90,7 +90,7 @@ if sys.platform != 'win32': sys.stderr.flush() self.returncode = None - r, w = os.pipe() + r, w = os.pipe(cloexec=True) self.sentinel = r self.pid = os.fork() @@ -211,7 +211,7 @@ else: prep_data = get_preparation_data(process_obj._name) # create pipe for communication with child - rfd, wfd = os.pipe() + rfd, wfd = os.pipe(cloexec=True) # get handle for read end of the pipe and make it inheritable rhandle = duplicate(msvcrt.get_osfhandle(rfd), inheritable=True) diff -r bc88690df059 Lib/multiprocessing/process.py --- a/Lib/multiprocessing/process.py Tue Jan 29 13:35:00 2013 +0100 +++ b/Lib/multiprocessing/process.py Tue Jan 29 14:00:58 2013 +0100 @@ -241,7 +241,7 @@ class Process(object): if sys.stdin is not None: try: sys.stdin.close() - sys.stdin = open(os.devnull) + sys.stdin = open(os.devnull, cloexec=True) except (OSError, ValueError): pass old_process = _current_process diff -r bc88690df059 Lib/subprocess.py --- a/Lib/subprocess.py Tue Jan 29 13:35:00 2013 +0100 +++ b/Lib/subprocess.py Tue Jan 29 14:00:58 2013 +0100 @@ -793,15 +793,15 @@ class Popen(object): errread = msvcrt.open_osfhandle(errread.Detach(), 0) if p2cwrite != -1: - self.stdin = io.open(p2cwrite, 'wb', bufsize) + self.stdin = io.open(p2cwrite, 'wb', bufsize, cloexec=True) if universal_newlines: self.stdin = io.TextIOWrapper(self.stdin, write_through=True) if c2pread != -1: - self.stdout = io.open(c2pread, 'rb', bufsize) + self.stdout = io.open(c2pread, 'rb', bufsize, cloexec=True) if universal_newlines: self.stdout = io.TextIOWrapper(self.stdout) if errread != -1: - self.stderr = io.open(errread, 'rb', bufsize) + self.stderr = io.open(errread, 'rb', bufsize, cloexec=True) if universal_newlines: self.stderr = io.TextIOWrapper(self.stderr) @@ -870,7 +870,7 @@ class Popen(object): def _get_devnull(self): if not hasattr(self, '_devnull'): - self._devnull = os.open(os.devnull, os.O_RDWR) + self._devnull = os.open(os.devnull, os.O_RDWR, cloexec=True) return self._devnull def communicate(self, input=None, timeout=None):