[Python-checkins] cpython (2.7): Issue #10527: Use poll() instead of select() for multiprocessing pipes

richard.oudkerk python-checkins at python.org
Tue Jan 15 01:50:13 CET 2013


http://hg.python.org/cpython/rev/da5e520a7ba5
changeset: 81506:da5e520a7ba5
branch: 2.7
parent: 81501:ce869b05762c
user: Richard Oudkerk <shibturn at gmail.com>
date: Mon Jan 14 23:09:14 2013 +0000
summary:
 Issue #10527: Use poll() instead of select() for multiprocessing pipes
files:
 Misc/NEWS | 2 +
 Modules/_multiprocessing/socket_connection.c | 33 ++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -186,6 +186,8 @@
 Library
 -------
 
+- Issue #10527: Use poll() instead of select() for multiprocessing pipes.
+
 - Issue #9720: zipfile now writes correct local headers for files larger than
 4 GiB.
 
diff --git a/Modules/_multiprocessing/socket_connection.c b/Modules/_multiprocessing/socket_connection.c
--- a/Modules/_multiprocessing/socket_connection.c
+++ b/Modules/_multiprocessing/socket_connection.c
@@ -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)
@@ -158,6 +162,34 @@
 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;
 
@@ -193,6 +225,7 @@
 assert(res == 0);
 return FALSE;
 }
+#endif
 }
 
 /*
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /