diff --git a/Lib/selectors.py b/Lib/selectors.py index 4e9ae6ec3f4..ad7afe2aab5 100644 --- a/Lib/selectors.py +++ b/Lib/selectors.py @@ -418,7 +418,12 @@ def select(self, timeout=None): # 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 544ea7bba6c..2625c127a6e 100644 --- a/Lib/test/test_selectors.py +++ b/Lib/test/test_selectors.py @@ -316,6 +316,11 @@ def test_selector(self): 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)