mirror of
https://github.com/python/cpython
synced 2024-09-16 03:59:56 +00:00
gh-106751: Optimize KqueueSelector.select() for many iteration case (gh-106864)
This commit is contained in:
parent
663854d73b
commit
7513e2e7e4
|
@ -547,23 +547,21 @@ def select(self, timeout=None):
|
||||||
# If max_ev is 0, kqueue will ignore the timeout. For consistent
|
# If max_ev is 0, kqueue will ignore the timeout. For consistent
|
||||||
# behavior with the other selector classes, we prevent that here
|
# behavior with the other selector classes, we prevent that here
|
||||||
# (using max). See https://bugs.python.org/issue29255
|
# (using max). See https://bugs.python.org/issue29255
|
||||||
max_ev = max(len(self._fd_to_key), 1)
|
max_ev = len(self._fd_to_key) or 1
|
||||||
ready = []
|
ready = []
|
||||||
try:
|
try:
|
||||||
kev_list = self._selector.control(None, max_ev, timeout)
|
kev_list = self._selector.control(None, max_ev, timeout)
|
||||||
except InterruptedError:
|
except InterruptedError:
|
||||||
return ready
|
return ready
|
||||||
|
|
||||||
|
fd_to_key_get = self._fd_to_key.get
|
||||||
for kev in kev_list:
|
for kev in kev_list:
|
||||||
fd = kev.ident
|
fd = kev.ident
|
||||||
flag = kev.filter
|
flag = kev.filter
|
||||||
events = 0
|
key = fd_to_key_get(fd)
|
||||||
if flag == select.KQ_FILTER_READ:
|
|
||||||
events |= EVENT_READ
|
|
||||||
if flag == select.KQ_FILTER_WRITE:
|
|
||||||
events |= EVENT_WRITE
|
|
||||||
|
|
||||||
key = self._fd_to_key.get(fd)
|
|
||||||
if key:
|
if key:
|
||||||
|
events = ((flag == select.KQ_FILTER_READ and EVENT_READ)
|
||||||
|
| (flag == select.KQ_FILTER_WRITE and EVENT_WRITE))
|
||||||
ready.append((key, events & key.events))
|
ready.append((key, events & key.events))
|
||||||
return ready
|
return ready
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Optimize :meth:`KqueueSelector.select` for many iteration case. Patch By
|
||||||
|
Dong-hee Na.
|
Loading…
Reference in a new issue