[3.6] bpo-32568: make select.epoll() and its docs consistent (GH-7840… · python/cpython@db7ac30 · GitHub
Skip to content

Commit db7ac30

Browse files
authored
[3.6] bpo-32568: make select.epoll() and its docs consistent (GH-7840) (GH-8025)
* `flags` is indeed deprecated, but there is a validation on its value for backwards compatibility reasons. This adds mention of this in the docs. * The docs say that `sizehint` is deprecated and ignored, but it is still used when `epoll_create1()` is unavailable. This adds mention of this in the docs. * `sizehint=-1` is acceptable again, and is replaced with `FD_SETSIZE-1`. This is needed to have a default value available at the Python level, since `FD_SETSIZE` is not exposed to Python. (see: bpo-31938) * Reject `sizehint=0` since it is invalid to pass on to `epoll_create()`. The relevant tests have also been updated. (cherry picked from commit 0cdf5f4)
1 parent b2e88fc commit db7ac30

4 files changed

Lines changed: 36 additions & 13 deletions

File tree

Doc/library/select.rst

Lines changed: 10 additions & 1 deletion

Lib/test/test_epoll.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ def test_create(self):
7474
ep.close()
7575
self.assertTrue(ep.closed)
7676
self.assertRaises(ValueError, ep.fileno)
77+
7778
if hasattr(select, "EPOLL_CLOEXEC"):
78-
select.epoll(select.EPOLL_CLOEXEC).close()
79-
self.assertRaises(OSError, select.epoll, flags=12356)
79+
select.epoll(-1, select.EPOLL_CLOEXEC).close()
80+
select.epoll(flags=select.EPOLL_CLOEXEC).close()
81+
select.epoll(flags=0).close()
8082

8183
def test_badcreate(self):
8284
self.assertRaises(TypeError, select.epoll, 1, 2, 3)
@@ -86,6 +88,13 @@ def test_badcreate(self):
8688
self.assertRaises(TypeError, select.epoll, ['foo'])
8789
self.assertRaises(TypeError, select.epoll, {})
8890

91+
self.assertRaises(ValueError, select.epoll, 0)
92+
self.assertRaises(ValueError, select.epoll, -2)
93+
self.assertRaises(ValueError, select.epoll, sizehint=-2)
94+
95+
if hasattr(select, "EPOLL_CLOEXEC"):
96+
self.assertRaises(OSError, select.epoll, flags=12356)
97+
8998
def test_context_manager(self):
9099
with select.epoll(16) as ep:
91100
self.assertGreater(ep.fileno(), 0)
@@ -115,19 +124,19 @@ def test_add(self):
115124
try:
116125
# TypeError: argument must be an int, or have a fileno() method.
117126
self.assertRaises(TypeError, ep.register, object(),
118-
select.EPOLLIN | select.EPOLLOUT)
127+
select.EPOLLIN | select.EPOLLOUT)
119128
self.assertRaises(TypeError, ep.register, None,
120-
select.EPOLLIN | select.EPOLLOUT)
129+
select.EPOLLIN | select.EPOLLOUT)
121130
# ValueError: file descriptor cannot be a negative integer (-1)
122131
self.assertRaises(ValueError, ep.register, -1,
123-
select.EPOLLIN | select.EPOLLOUT)
132+
select.EPOLLIN | select.EPOLLOUT)
124133
# OSError: [Errno 9] Bad file descriptor
125134
self.assertRaises(OSError, ep.register, 10000,
126-
select.EPOLLIN | select.EPOLLOUT)
135+
select.EPOLLIN | select.EPOLLOUT)
127136
# registering twice also raises an exception
128137
ep.register(server, select.EPOLLIN | select.EPOLLOUT)
129138
self.assertRaises(OSError, ep.register, server,
130-
select.EPOLLIN | select.EPOLLOUT)
139+
select.EPOLLIN | select.EPOLLOUT)
131140
finally:
132141
ep.close()
133142

@@ -158,9 +167,9 @@ def test_control_and_wait(self):
158167

159168
ep = select.epoll(16)
160169
ep.register(server.fileno(),
161-
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
170+
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
162171
ep.register(client.fileno(),
163-
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
172+
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
164173

165174
now = time.monotonic()
166175
events = ep.poll(1, 4)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make select.epoll() and its documentation consistent regarding *sizehint* and
2+
*flags*.

Modules/selectmodule.c

Lines changed: 6 additions & 3 deletions

0 commit comments

Comments
 (0)