This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpython-2.6.6-use-poll-for-multiprocessing-socket-connection.patch
82 lines (76 loc) · 2.76 KB
/
python-2.6.6-use-poll-for-multiprocessing-socket-connection.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
diff -up Python-2.6.6/Lib/test/test_multiprocessing.py.use-poll-for-multiprocessing-socket-connection Python-2.6.6/Lib/test/test_multiprocessing.py
--- Python-2.6.6/Lib/test/test_multiprocessing.py.use-poll-for-multiprocessing-socket-connection 2011-06-30 19:44:47.892755812 -0400
+++ Python-2.6.6/Lib/test/test_multiprocessing.py 2011-06-30 19:52:55.789497774 -0400
@@ -65,6 +65,13 @@ HAVE_GETVALUE = not getattr(_multiproces
WIN32 = (sys.platform == "win32")
+try:
+ from select import poll as test_for_poll
+ HAVE_POLL = True
+ del test_for_poll
+except ImportError:
+ HAVE_POLL = False
+
#
# Creates a wrapper for a function which records the time it takes to finish
#
@@ -1726,7 +1733,12 @@ class TestInvalidHandle(unittest.TestCas
if WIN32:
return
conn = _multiprocessing.Connection(44977608)
- self.assertRaises(IOError, conn.poll)
+ if HAVE_POLL:
+ # conn.poll is implemented in terms of the "poll" syscall:
+ self.assertEquals(conn.poll(), False)
+ else:
+ # conn.poll is implemented in terms of the "select" syscall:
+ self.assertRaises(IOError, conn.poll)
self.assertRaises(IOError, _multiprocessing.Connection, -1)
#
# Functions used to create test cases from the base ones in this module
diff -up Python-2.6.6/Modules/_multiprocessing/socket_connection.c.use-poll-for-multiprocessing-socket-connection Python-2.6.6/Modules/_multiprocessing/socket_connection.c
--- Python-2.6.6/Modules/_multiprocessing/socket_connection.c.use-poll-for-multiprocessing-socket-connection 2010-05-09 11:15:40.000000000 -0400
+++ Python-2.6.6/Modules/_multiprocessing/socket_connection.c 2011-06-30 19:24:24.391875469 -0400
@@ -7,6 +7,9 @@
*/
#include "multiprocessing.h"
+#ifdef HAVE_POLL
+#include <poll.h>
+#endif
#ifdef MS_WINDOWS
# define WRITE(h, buffer, length) send((SOCKET)h, buffer, length, 0)
@@ -152,6 +155,29 @@ conn_recv_string(ConnectionObject *conn,
* Check whether any data is available for reading -- neg timeout blocks
*/
+#ifdef HAVE_POLL
+static int
+conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
+{
+ int res;
+ struct pollfd p;
+
+ p.fd = (int)conn->handle;
+ p.events = POLLIN | POLLPRI;
+ p.revents = 0;
+
+ res = poll(&p, 1, (int)(timeout * 1000));
+
+ if (res < 0) {
+ return MP_SOCKET_ERROR;
+ } else if (p.revents & (POLLIN | POLLPRI)) {
+ return TRUE;
+ } else {
+ assert(res == 0);
+ return FALSE;
+ }
+}
+#else
static int
conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
{
@@ -191,6 +217,7 @@ conn_poll(ConnectionObject *conn, double
return FALSE;
}
}
+#endif
/*
* "connection.h" defines the Connection type using defs above