]> granicus.if.org Git - python/commitdiff
selectors: Make sure EpollSelecrtor.select() works when no FD is registered.
authorYury Selivanov <yselivanov@sprymix.com>
Mon, 8 Dec 2014 17:21:58 +0000 (12:21 -0500)
committerYury Selivanov <yselivanov@sprymix.com>
Mon, 8 Dec 2014 17:21:58 +0000 (12:21 -0500)
Closes issue #23009.

Lib/selectors.py
Lib/test/test_selectors.py

index 9be9225537f0baf5383f96f202366eecf0e1e232..25b8d798219ef968adafdf7257857aaf49ffee76 100644 (file)
@@ -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)
index 46026be0aa60bb972cbfa0c3c246f1be5cbbd9d0..c08a3c498916de30e0a95f069e5d6ac6dc8a6bff 100644 (file)
@@ -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)