def _scan(self): with closing(select.epoll()) as epoll: with _monitoring_socket(self._queue, self._groups, epoll) as sock: with _pipetrick(epoll) as self._pipetrick: self._scanning_started.set() while True: if self._timeout: timeout = self._end_time - monotonic_time() # timeout expired if timeout <= 0: self._scanning_stopped.set() self._queue.put(_TIMEOUT_FLAG) break else: timeout = -1 events = NoIntrPoll(epoll.poll, timeout=timeout) # poll timeouted if len(events) == 0: self._scanning_stopped.set() self._queue.put(_TIMEOUT_FLAG) break # stopped by pipetrick elif (self._pipetrick[0], select.POLLIN) in events: NoIntrCall(os.read, self._pipetrick[0], 1) self._queue.put(_STOP_FLAG) break _nl_recvmsgs_default(sock)
def _wait_for_events(self): """ Wait for an epoll event and handle channels' timeout. """ events = NoIntrPoll(self._epoll.poll, 1) for (fileno, event) in events: self._handle_event(fileno, event) else: self._update_channels() if (self._timeout is not None) and (self._timeout > 0): self._handle_timeouts() self._handle_unconnected()