mirror of https://github.com/python/cpython
gh-106751: Optimize _PolllikeSelector for many iteration case (gh-106884)
This commit is contained in:
parent
1e1f4e91a9
commit
832c37d42a
|
@ -339,11 +339,8 @@ class _PollLikeSelector(_BaseSelectorImpl):
|
|||
|
||||
def register(self, fileobj, events, data=None):
|
||||
key = super().register(fileobj, events, data)
|
||||
poller_events = 0
|
||||
if events & EVENT_READ:
|
||||
poller_events |= self._EVENT_READ
|
||||
if events & EVENT_WRITE:
|
||||
poller_events |= self._EVENT_WRITE
|
||||
poller_events = ((events & EVENT_READ and self._EVENT_READ)
|
||||
| (events & EVENT_WRITE and self._EVENT_WRITE) )
|
||||
try:
|
||||
self._selector.register(key.fd, poller_events)
|
||||
except:
|
||||
|
@ -369,11 +366,8 @@ class _PollLikeSelector(_BaseSelectorImpl):
|
|||
|
||||
changed = False
|
||||
if events != key.events:
|
||||
selector_events = 0
|
||||
if events & EVENT_READ:
|
||||
selector_events |= self._EVENT_READ
|
||||
if events & EVENT_WRITE:
|
||||
selector_events |= self._EVENT_WRITE
|
||||
selector_events = ((events & EVENT_READ and self._EVENT_READ)
|
||||
| (events & EVENT_WRITE and self._EVENT_WRITE))
|
||||
try:
|
||||
self._selector.modify(key.fd, selector_events)
|
||||
except:
|
||||
|
@ -404,15 +398,13 @@ class _PollLikeSelector(_BaseSelectorImpl):
|
|||
fd_event_list = self._selector.poll(timeout)
|
||||
except InterruptedError:
|
||||
return ready
|
||||
for fd, event in fd_event_list:
|
||||
events = 0
|
||||
if event & ~self._EVENT_READ:
|
||||
events |= EVENT_WRITE
|
||||
if event & ~self._EVENT_WRITE:
|
||||
events |= EVENT_READ
|
||||
|
||||
key = self._fd_to_key.get(fd)
|
||||
fd_to_key_get = self._fd_to_key.get
|
||||
for fd, event in fd_event_list:
|
||||
key = fd_to_key_get(fd)
|
||||
if key:
|
||||
events = ((event & ~self._EVENT_READ and EVENT_WRITE)
|
||||
| (event & ~self._EVENT_WRITE and EVENT_READ))
|
||||
ready.append((key, events & key.events))
|
||||
return ready
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Optimize :meth:`_PollLikeSelector.select` for many iteration case.
|
Loading…
Reference in New Issue