aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2014-12-08 12:21:58 -0500
committerYury Selivanov <yselivanov@sprymix.com>2014-12-08 12:21:58 -0500
commitd60ef4aa9daff89af06117e7e2ae83adfb8c9dce (patch)
treeda8f95c1b944a38a48eecbbc78119b4a659de992
parente3b743cd3ee4e5adf1598dbef002779eb5c12989 (diff)
downloadcpython-d60ef4aa9daff89af06117e7e2ae83adfb8c9dce.tar.gz
cpython-d60ef4aa9daff89af06117e7e2ae83adfb8c9dce.zip
selectors: Make sure EpollSelecrtor.select() works when no FD is registered.
Closes issue #23009.
-rw-r--r--Lib/selectors.py7
-rw-r--r--Lib/test/test_selectors.py5
2 files changed, 11 insertions, 1 deletions
diff --git a/Lib/selectors.py b/Lib/selectors.py
index 9be9225537f..25b8d798219 100644
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -418,7 +418,12 @@ if hasattr(select, 'epoll'):
# epoll_wait() has a resolution of 1 millisecond, round away
# from zero to wait *at least* timeout seconds.
timeout = math.ceil(timeout * 1e3) * 1e-3
- max_ev = len(self._fd_to_key)
+
+ # epoll_wait() expectcs `maxevents` to be greater than zero;
+ # we want to make sure that `select()` can be called when no
+ # FD is registered.
+ max_ev = max(len(self._fd_to_key), 1)
+
ready = []
try:
fd_event_list = self._epoll.poll(timeout, max_ev)
diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py
index 46026be0aa6..c08a3c49891 100644
--- a/Lib/test/test_selectors.py
+++ b/Lib/test/test_selectors.py
@@ -319,6 +319,11 @@ class BaseSelectorTestCase(unittest.TestCase):
self.assertEqual(bufs, [MSG] * NUM_SOCKETS)
+ def test_empty_select(self):
+ s = self.SELECTOR()
+ self.addCleanup(s.close)
+ self.assertEqual(s.select(timeout=0), [])
+
def test_timeout(self):
s = self.SELECTOR()
self.addCleanup(s.close)