From: Antoine Pitrou Date: Sat, 7 Apr 2012 20:38:52 +0000 (+0200) Subject: Issue #14522: Avoid duplicating socket handles in multiprocessing.connection. X-Git-Tag: v3.3.0a3~289 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=df97cbe7a1866a9d16d20bed70054f344a406e08;p=python Issue #14522: Avoid duplicating socket handles in multiprocessing.connection. Patch by sbt. --- diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index 4e4544314e..90c1ea7abf 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -591,10 +591,7 @@ class SocketListener(object): def accept(self): s, self._last_accepted = self._socket.accept() - fd = duplicate(s.fileno()) - conn = Connection(fd) - s.close() - return conn + return Connection(s.detach()) def close(self): self._socket.close() @@ -609,9 +606,7 @@ def SocketClient(address): family = address_type(address) with socket.socket( getattr(socket, family) ) as s: s.connect(address) - fd = duplicate(s.fileno()) - conn = Connection(fd) - return conn + return Connection(s.detach()) # # Definitions for connections based on named pipes @@ -665,7 +660,7 @@ if sys.platform == 'win32': def _finalize_pipe_listener(queue, address): sub_debug('closing listener with address=%r', address) for handle in queue: - close(handle) + win32.CloseHandle(handle) def PipeClient(address): ''' @@ -885,7 +880,3 @@ else: raise if timeout is not None: timeout = deadline - time.time() - - -# Late import because of circular import -from multiprocessing.forking import duplicate, close diff --git a/Misc/NEWS b/Misc/NEWS index 5164fbf08f..af1b5d0b1e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,9 @@ Core and Builtins Library ------- +- Issue #14522: Avoid duplicating socket handles in multiprocessing.connection. + Patch by sbt. + - Don't Py_DECREF NULL variable in io.IncrementalNewlineDecoder. - Issue #8515: Set __file__ when run file in IDLE.