|
|
2938c66 |
diff -up Python-2.7.3/Doc/library/asyncore.rst.use-poll-for-multiprocessing-socket-connection Python-2.7.3/Doc/library/asyncore.rst
|
|
|
2938c66 |
--- Python-2.7.3/Doc/library/asyncore.rst.use-poll-for-multiprocessing-socket-connection 2013-02-21 15:21:41.204812979 -0500
|
|
|
2938c66 |
+++ Python-2.7.3/Doc/library/asyncore.rst 2013-02-21 15:21:41.211812976 -0500
|
|
|
2938c66 |
@@ -318,13 +318,10 @@ connections and dispatches the incoming
|
|
|
2938c66 |
|
|
|
2938c66 |
def handle_accept(self):
|
|
|
2938c66 |
pair = self.accept()
|
|
|
2938c66 |
- if pair is None:
|
|
|
2938c66 |
- pass
|
|
|
2938c66 |
- else:
|
|
|
2938c66 |
+ if pair is not None:
|
|
|
2938c66 |
sock, addr = pair
|
|
|
2938c66 |
print 'Incoming connection from %s' % repr(addr)
|
|
|
2938c66 |
handler = EchoHandler(sock)
|
|
|
2938c66 |
|
|
|
2938c66 |
server = EchoServer('localhost', 8080)
|
|
|
2938c66 |
asyncore.loop()
|
|
|
2938c66 |
-
|
|
|
2938c66 |
diff -up Python-2.7.3/Lib/multiprocessing/connection.py.use-poll-for-multiprocessing-socket-connection Python-2.7.3/Lib/multiprocessing/connection.py
|
|
|
2938c66 |
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
|
|
|
2938c66 |
--- Python-2.7.3/Lib/test/test_multiprocessing.py.use-poll-for-multiprocessing-socket-connection 2013-02-21 15:21:41.199812979 -0500
|
|
|
2938c66 |
+++ Python-2.7.3/Lib/test/test_multiprocessing.py 2013-02-21 15:21:41.208812978 -0500
|
|
|
2938c66 |
@@ -1452,6 +1452,7 @@ class _TestConnection(BaseTestCase):
|
|
|
2938c66 |
self.assertTimingAlmostEqual(poll.elapsed, TIMEOUT1)
|
|
|
2938c66 |
|
|
|
2938c66 |
conn.send(None)
|
|
|
2938c66 |
+ time.sleep(.1)
|
|
|
2938c66 |
|
|
|
2938c66 |
self.assertEqual(poll(TIMEOUT1), True)
|
|
|
2938c66 |
self.assertTimingAlmostEqual(poll.elapsed, 0)
|
|
|
2938c66 |
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
|
|
|
2938c66 |
--- Python-2.7.3/Modules/_multiprocessing/socket_connection.c.use-poll-for-multiprocessing-socket-connection 2013-02-21 15:21:41.201812979 -0500
|
|
|
2938c66 |
+++ Python-2.7.3/Modules/_multiprocessing/socket_connection.c 2013-02-21 15:21:41.215812978 -0500
|
|
|
2938c66 |
@@ -8,6 +8,10 @@
|
|
|
2938c66 |
|
|
|
2938c66 |
#include "multiprocessing.h"
|
|
|
2938c66 |
|
|
|
2938c66 |
+#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)
|
|
|
2938c66 |
+# include "poll.h"
|
|
|
2938c66 |
+#endif
|
|
|
2938c66 |
+
|
|
|
2938c66 |
#ifdef MS_WINDOWS
|
|
|
2938c66 |
# define WRITE(h, buffer, length) send((SOCKET)h, buffer, length, 0)
|
|
|
2938c66 |
# define READ(h, buffer, length) recv((SOCKET)h, buffer, length, 0)
|
|
|
2938c66 |
@@ -155,6 +159,34 @@ conn_recv_string(ConnectionObject *conn,
|
|
|
2938c66 |
static int
|
|
|
2938c66 |
conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
|
|
|
2938c66 |
{
|
|
|
2938c66 |
+#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)
|
|
|
2938c66 |
+ int res;
|
|
|
2938c66 |
+ struct pollfd p;
|
|
|
2938c66 |
+
|
|
|
2938c66 |
+ p.fd = (int)conn->handle;
|
|
|
2938c66 |
+ p.events = POLLIN | POLLPRI;
|
|
|
2938c66 |
+ p.revents = 0;
|
|
|
2938c66 |
+
|
|
|
2938c66 |
+ if (timeout < 0) {
|
|
|
2938c66 |
+ res = poll(&p, 1, -1);
|
|
|
2938c66 |
+ } else {
|
|
|
2938c66 |
+ res = poll(&p, 1, (int)(timeout * 1000 + 0.5));
|
|
|
2938c66 |
+ }
|
|
|
2938c66 |
+
|
|
|
2938c66 |
+ if (res < 0) {
|
|
|
2938c66 |
+ return MP_SOCKET_ERROR;
|
|
|
2938c66 |
+ } else if (p.revents & (POLLNVAL|POLLERR)) {
|
|
|
2938c66 |
+ Py_BLOCK_THREADS
|
|
|
2938c66 |
+ PyErr_SetString(PyExc_IOError, "poll() gave POLLNVAL or POLLERR");
|
|
|
2938c66 |
+ Py_UNBLOCK_THREADS
|
|
|
2938c66 |
+ return MP_EXCEPTION_HAS_BEEN_SET;
|
|
|
2938c66 |
+ } else if (p.revents != 0) {
|
|
|
2938c66 |
+ return TRUE;
|
|
|
2938c66 |
+ } else {
|
|
|
2938c66 |
+ assert(res == 0);
|
|
|
2938c66 |
+ return FALSE;
|
|
|
2938c66 |
+ }
|
|
|
2938c66 |
+#else
|
|
|
2938c66 |
int res;
|
|
|
2938c66 |
fd_set rfds;
|
|
|
2938c66 |
|
|
|
2938c66 |
@@ -190,6 +222,7 @@ conn_poll(ConnectionObject *conn, double
|
|
|
2938c66 |
assert(res == 0);
|
|
|
2938c66 |
return FALSE;
|
|
|
2938c66 |
}
|
|
|
2938c66 |
+#endif
|
|
|
2938c66 |
}
|
|
|
2938c66 |
|
|
|
2938c66 |
/*
|