]> granicus.if.org Git - python/commitdiff
Issue #14522: Avoid duplicating socket handles in multiprocessing.connection.
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 7 Apr 2012 20:38:52 +0000 (22:38 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 7 Apr 2012 20:38:52 +0000 (22:38 +0200)
Patch by sbt.

Lib/multiprocessing/connection.py
Misc/NEWS

index 4e4544314eebd14e5b0adcaa19f33d0f94bdb615..90c1ea7abf5fae92ecd9e567274f3258e95e4648 100644 (file)
@@ -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
index 5164fbf08f2210e850a80177322248f5af87cb28..af1b5d0b1e39e244c55d060acae93464bbb727d9 100644 (file)
--- 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.