[python] 2.7.3-27: port _multiprocessing.Connection to use the "poll" syscall (patch 172; rhbz#849992)

dmalcolm dmalcolm at fedoraproject.org
Thu Feb 21 22:12:26 UTC 2013


commit 2938c661975c582a54dca69a7dc212f12673afa8
Author: David Malcolm <dmalcolm at redhat.com>
Date:   Thu Feb 21 17:11:13 2013 -0500

    2.7.3-27: port _multiprocessing.Connection to use the "poll" syscall (patch 172; rhbz#849992)
    
    * Thu Feb 21 2013 David Malcolm <dmalcolm at redhat.com> - 2.7.3-27
    - port _multiprocessing.Connection.poll() to use the "poll" syscall, rather
    than "select", allowing large numbers of subprocesses (patch 172;
    rhbz#849992)

 ...oll-for-multiprocessing-socket-connection.patch |   87 ++++++++++++++++++++
 python.spec                                        |   22 +++++-
 2 files changed, 108 insertions(+), 1 deletions(-)
---
diff --git a/00172-use-poll-for-multiprocessing-socket-connection.patch b/00172-use-poll-for-multiprocessing-socket-connection.patch
new file mode 100644
index 0000000..5b2f626
--- /dev/null
+++ b/00172-use-poll-for-multiprocessing-socket-connection.patch
@@ -0,0 +1,87 @@
+diff -up Python-2.7.3/Doc/library/asyncore.rst.use-poll-for-multiprocessing-socket-connection Python-2.7.3/Doc/library/asyncore.rst
+--- Python-2.7.3/Doc/library/asyncore.rst.use-poll-for-multiprocessing-socket-connection	2013-02-21 15:21:41.204812979 -0500
++++ Python-2.7.3/Doc/library/asyncore.rst	2013-02-21 15:21:41.211812976 -0500
+@@ -318,13 +318,10 @@ connections and dispatches the incoming
+ 
+         def handle_accept(self):
+             pair = self.accept()
+-            if pair is None:
+-                pass
+-            else:
++            if pair is not None:
+                 sock, addr = pair
+                 print 'Incoming connection from %s' % repr(addr)
+                 handler = EchoHandler(sock)
+ 
+     server = EchoServer('localhost', 8080)
+     asyncore.loop()
+-
+diff -up Python-2.7.3/Lib/multiprocessing/connection.py.use-poll-for-multiprocessing-socket-connection Python-2.7.3/Lib/multiprocessing/connection.py
+diff -up Python-2.7.3/Lib/test/test_multiprocessing.py.use-poll-for-multiprocessing-socket-connection Python-2.7.3/Lib/test/test_multiprocessing.py
+--- Python-2.7.3/Lib/test/test_multiprocessing.py.use-poll-for-multiprocessing-socket-connection	2013-02-21 15:21:41.199812979 -0500
++++ Python-2.7.3/Lib/test/test_multiprocessing.py	2013-02-21 15:21:41.208812978 -0500
+@@ -1452,6 +1452,7 @@ class _TestConnection(BaseTestCase):
+         self.assertTimingAlmostEqual(poll.elapsed, TIMEOUT1)
+ 
+         conn.send(None)
++        time.sleep(.1)
+ 
+         self.assertEqual(poll(TIMEOUT1), True)
+         self.assertTimingAlmostEqual(poll.elapsed, 0)
+diff -up Python-2.7.3/Modules/_multiprocessing/socket_connection.c.use-poll-for-multiprocessing-socket-connection Python-2.7.3/Modules/_multiprocessing/socket_connection.c
+--- Python-2.7.3/Modules/_multiprocessing/socket_connection.c.use-poll-for-multiprocessing-socket-connection	2013-02-21 15:21:41.201812979 -0500
++++ Python-2.7.3/Modules/_multiprocessing/socket_connection.c	2013-02-21 15:21:41.215812978 -0500
+@@ -8,6 +8,10 @@
+ 
+ #include "multiprocessing.h"
+ 
++#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)
++#  include "poll.h"
++#endif
++
+ #ifdef MS_WINDOWS
+ #  define WRITE(h, buffer, length) send((SOCKET)h, buffer, length, 0)
+ #  define READ(h, buffer, length) recv((SOCKET)h, buffer, length, 0)
+@@ -155,6 +159,34 @@ conn_recv_string(ConnectionObject *conn,
+ static int
+ conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
+ {
++#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)
++    int res;
++    struct pollfd p;
++
++    p.fd = (int)conn->handle;
++    p.events = POLLIN | POLLPRI;
++    p.revents = 0;
++
++    if (timeout < 0) {
++        res = poll(&p, 1, -1);
++    } else {
++        res = poll(&p, 1, (int)(timeout * 1000 + 0.5));
++    }
++
++    if (res < 0) {
++        return MP_SOCKET_ERROR;
++    } else if (p.revents & (POLLNVAL|POLLERR)) {
++        Py_BLOCK_THREADS
++        PyErr_SetString(PyExc_IOError, "poll() gave POLLNVAL or POLLERR");
++        Py_UNBLOCK_THREADS
++        return MP_EXCEPTION_HAS_BEEN_SET;
++    } else if (p.revents != 0) {
++        return TRUE;
++    } else {
++        assert(res == 0);
++        return FALSE;
++    }
++#else
+     int res;
+     fd_set rfds;
+ 
+@@ -190,6 +222,7 @@ conn_poll(ConnectionObject *conn, double
+         assert(res == 0);
+         return FALSE;
+     }
++#endif
+ }
+ 
+ /*
diff --git a/python.spec b/python.spec
index 1309c89..71ddbfd 100644
--- a/python.spec
+++ b/python.spec
@@ -106,7 +106,7 @@ Summary: An interpreted, interactive, object-oriented programming language
 Name: %{python}
 # Remember to also rebase python-docs when changing this:
 Version: 2.7.3
-Release: 26%{?dist}
+Release: 27%{?dist}
 License: Python
 Group: Development/Languages
 Requires: %{python}-libs%{?_isa} = %{version}-%{release}
@@ -792,6 +792,20 @@ Patch170: 00170-gc-assertions.patch
 # (rhbz#907383; http://bugs.python.org/issue15340)
 Patch171: 00171-raise-correct-exception-when-dev-urandom-is-missing.patch
 
+# 00172 #
+# Port _multiprocessing.Connection.poll() to use the "poll" syscall, rather
+# than "select", allowing large numbers of subprocesses
+#
+# Based on this sequence of upstream patches to 2.7:
+#   http://hg.python.org/cpython/rev/c5c27b84d7af/
+#   http://hg.python.org/cpython/rev/7cf4ea64f603/
+#   http://hg.python.org/cpython/rev/da5e520a7ba5/
+#   http://hg.python.org/cpython/rev/f07435fa6736/
+#
+#(rhbz#849992; http://bugs.python.org/issue10527)
+Patch172: 00172-use-poll-for-multiprocessing-socket-connection.patch
+
+
 # (New patches go here ^^^)
 #
 # When adding new patches to "python" and "python3" in Fedora 17 onwards,
@@ -1130,6 +1144,7 @@ mv Modules/cryptmodule.c Modules/_cryptmodule.c
 %patch169 -p1
 %patch170 -p1
 %patch171 -p1 -b .raise-correct-exception-when-dev-urandom-is-missing
+%patch172 -p1
 
 
 # This shouldn't be necesarry, but is right now (2.2a3)
@@ -1962,6 +1977,11 @@ rm -fr %{buildroot}
 # ======================================================
 
 %changelog
+* Thu Feb 21 2013 David Malcolm <dmalcolm at redhat.com> - 2.7.3-27
+- port _multiprocessing.Connection.poll() to use the "poll" syscall, rather
+than "select", allowing large numbers of subprocesses (patch 172;
+rhbz#849992)
+
 * Thu Feb 21 2013 David Malcolm <dmalcolm at redhat.com> - 2.7.3-26
 - raise correct exception in os.urandom() when /dev/urandom is missing
 (patch 171; rhbz#907383)


More information about the scm-commits mailing list