MCPcopy Index your code
hub / github.com/python/cpython / select

Method select

Lib/selectors.py:435–463  ·  view source on GitHub ↗
(self, timeout=None)

Source from the content-addressed store, hash-verified

433 return self._selector.fileno()
434
435 def select(self, timeout=None):
436 if timeout is None:
437 timeout = -1
438 elif timeout <= 0:
439 timeout = 0
440 else:
441 # epoll_wait() has a resolution of 1 millisecond, round away
442 # from zero to wait *at least* timeout seconds.
443 timeout = math.ceil(timeout * 1e3) * 1e-3
444
445 # epoll_wait() expects `maxevents` to be greater than zero;
446 # we want to make sure that `select()` can be called when no
447 # FD is registered.
448 max_ev = len(self._fd_to_key) or 1
449
450 ready = []
451 try:
452 fd_event_list = self._selector.poll(timeout, max_ev)
453 except InterruptedError:
454 return ready
455
456 fd_to_key = self._fd_to_key
457 for fd, event in fd_event_list:
458 key = fd_to_key.get(fd)
459 if key:
460 events = ((event & _NOT_EPOLLIN and EVENT_WRITE)
461 | (event & _NOT_EPOLLOUT and EVENT_READ))
462 ready.append((key, events & key.events))
463 return ready
464
465 def close(self):
466 self._selector.close()

Callers

nothing calls this directly

Calls 3

pollMethod · 0.45
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected