[Python-checkins] cpython (3.4): selectors: Make sure EpollSelecrtor.select() works when no FD is registered.

yury.selivanov python-checkins at python.org
Mon Dec 8 18:22:59 CET 2014


https://hg.python.org/cpython/rev/b2ee06684b6a
changeset:   93783:b2ee06684b6a
branch:      3.4
parent:      93781:6dfba0357c92
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Mon Dec 08 12:21:58 2014 -0500
summary:
  selectors: Make sure EpollSelecrtor.select() works when no FD is registered.

Closes issue #23009.

files:
  Lib/selectors.py           |  7 ++++++-
  Lib/test/test_selectors.py |  5 +++++
  2 files changed, 11 insertions(+), 1 deletions(-)


diff --git a/Lib/selectors.py b/Lib/selectors.py
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -418,7 +418,12 @@
                 # 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
--- a/Lib/test/test_selectors.py
+++ b/Lib/test/test_selectors.py
@@ -319,6 +319,11 @@
 
         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)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list