mirror of https://github.com/python/cpython
selectors: Make sure EpollSelecrtor.select() works when no FD is registered.
Closes issue #23009.
This commit is contained in:
parent
e3b743cd3e
commit
d60ef4aa9d
|
@ -418,7 +418,12 @@ if hasattr(select, 'epoll'):
|
||||||
# epoll_wait() has a resolution of 1 millisecond, round away
|
# epoll_wait() has a resolution of 1 millisecond, round away
|
||||||
# from zero to wait *at least* timeout seconds.
|
# from zero to wait *at least* timeout seconds.
|
||||||
timeout = math.ceil(timeout * 1e3) * 1e-3
|
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 = []
|
ready = []
|
||||||
try:
|
try:
|
||||||
fd_event_list = self._epoll.poll(timeout, max_ev)
|
fd_event_list = self._epoll.poll(timeout, max_ev)
|
||||||
|
|
|
@ -319,6 +319,11 @@ class BaseSelectorTestCase(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(bufs, [MSG] * NUM_SOCKETS)
|
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):
|
def test_timeout(self):
|
||||||
s = self.SELECTOR()
|
s = self.SELECTOR()
|
||||||
self.addCleanup(s.close)
|
self.addCleanup(s.close)
|
||||||
|
|
Loading…
Reference in New Issue