mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
bpo-29255: Wait in KqueueSelector.select when no fds are registered (GH-19508)
Also partially fixes bpo-25680 (there's still a discrepancy in behavior on Windows that needs to be fixed).
This commit is contained in:
parent
4b4e90a518
commit
ba1bcffe5c
3 changed files with 18 additions and 1 deletions
|
|
@ -552,7 +552,10 @@ if hasattr(select, 'kqueue'):
|
||||||
|
|
||||||
def select(self, timeout=None):
|
def select(self, timeout=None):
|
||||||
timeout = None if timeout is None else max(timeout, 0)
|
timeout = None if timeout is None else max(timeout, 0)
|
||||||
max_ev = len(self._fd_to_key)
|
# If max_ev is 0, kqueue will ignore the timeout. For consistent
|
||||||
|
# behavior with the other selector classes, we prevent that here
|
||||||
|
# (using max). See https://bugs.python.org/issue29255
|
||||||
|
max_ev = max(len(self._fd_to_key), 1)
|
||||||
ready = []
|
ready = []
|
||||||
try:
|
try:
|
||||||
kev_list = self._selector.control(None, max_ev, timeout)
|
kev_list = self._selector.control(None, max_ev, timeout)
|
||||||
|
|
|
||||||
|
|
@ -543,6 +543,19 @@ class KqueueSelectorTestCase(BaseSelectorTestCase, ScalableSelectorMixIn):
|
||||||
with self.assertRaises(KeyError):
|
with self.assertRaises(KeyError):
|
||||||
s.get_key(bad_f)
|
s.get_key(bad_f)
|
||||||
|
|
||||||
|
def test_empty_select_timeout(self):
|
||||||
|
# Issues #23009, #29255: Make sure timeout is applied when no fds
|
||||||
|
# are registered.
|
||||||
|
s = self.SELECTOR()
|
||||||
|
self.addCleanup(s.close)
|
||||||
|
|
||||||
|
t0 = time()
|
||||||
|
self.assertEqual(s.select(1), [])
|
||||||
|
t1 = time()
|
||||||
|
dt = t1 - t0
|
||||||
|
# Tolerate 2.0 seconds for very slow buildbots
|
||||||
|
self.assertTrue(0.8 <= dt <= 2.0, dt)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(selectors, 'DevpollSelector'),
|
@unittest.skipUnless(hasattr(selectors, 'DevpollSelector'),
|
||||||
"Test needs selectors.DevpollSelector")
|
"Test needs selectors.DevpollSelector")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Wait in `KqueueSelector.select` when no fds are registered
|
||||||
Loading…
Add table
Add a link
Reference in a new issue