]> granicus.if.org Git - python/commitdiff
Fix for issue 14725 for 2.7 branch
authorRichard Oudkerk <shibturn@gmail.com>
Sat, 5 May 2012 19:41:08 +0000 (20:41 +0100)
committerRichard Oudkerk <shibturn@gmail.com>
Sat, 5 May 2012 19:41:08 +0000 (20:41 +0100)
Lib/multiprocessing/connection.py
Lib/test/test_multiprocessing.py
Modules/_multiprocessing/win32_functions.c

index 530a8dfe4e5e028e73cb248a8cc8f5dd624865a4..a02793ff26b8ffc90a8c459990dcc42cc7b8cc19 100644 (file)
@@ -348,7 +348,10 @@ if sys.platform == 'win32':
             try:
                 win32.ConnectNamedPipe(handle, win32.NULL)
             except WindowsError, e:
-                if e.args[0] != win32.ERROR_PIPE_CONNECTED:
+                # ERROR_NO_DATA can occur if a client has already connected,
+                # written data and then disconnected -- see Issue 14725.
+                if e.args[0] not in (win32.ERROR_PIPE_CONNECTED,
+                                     win32.ERROR_NO_DATA):
                     raise
             return _multiprocessing.PipeConnection(handle)
 
index eeb768f7d7a509b48936796b66c1d980dfe695cc..0fe649799a3b6a2e60219edbc0bae375dfd6effe 100644 (file)
@@ -1669,6 +1669,23 @@ class _TestListenerClient(BaseTestCase):
             self.assertEqual(conn.recv(), 'hello')
             p.join()
             l.close()
+
+    def test_issue14725(self):
+        l = self.connection.Listener()
+        p = self.Process(target=self._test, args=(l.address,))
+        p.daemon = True
+        p.start()
+        time.sleep(1)
+        # On Windows the client process should by now have connected,
+        # written data and closed the pipe handle by now.  This causes
+        # ConnectNamdedPipe() to fail with ERROR_NO_DATA.  See Issue
+        # 14725.
+        conn = l.accept()
+        self.assertEqual(conn.recv(), 'hello')
+        conn.close()
+        p.join()
+        l.close()
+
 #
 # Test of sending connection and socket objects between processes
 #
index 1666aa9132f5b296043aa4ad882463b80c7e7c62..9425929469e27d0b49e82f18c24bde9cce8d746c 100644 (file)
@@ -244,6 +244,7 @@ create_win32_namespace(void)
     Py_INCREF(&Win32Type);
 
     WIN32_CONSTANT(F_DWORD, ERROR_ALREADY_EXISTS);
+    WIN32_CONSTANT(F_DWORD, ERROR_NO_DATA);
     WIN32_CONSTANT(F_DWORD, ERROR_PIPE_BUSY);
     WIN32_CONSTANT(F_DWORD, ERROR_PIPE_CONNECTED);
     WIN32_CONSTANT(F_DWORD, ERROR_SEM_TIMEOUT);