def _runWithExpiry(self, incomingHandler):
        xmitOnly = incomingHandler == TransmitOnly or \
                   isinstance(incomingHandler, TransmitOnly)

        if hasattr(self, '_aborting_run'): delattr(self, '_aborting_run')

        while not self.run_time.expired() and \
              (not hasattr(self, '_aborting_run') or
               (self._aborting_run and
                (len(self._transmitIntents) > 0 or
                 len(self._waitingTransmits) > 0))):

            if xmitOnly:
                if not self._transmitIntents and not self._waitingTransmits:
                    return 0
            else:
                while self._incomingEnvelopes:
                    rEnv = self._incomingEnvelopes.pop(0)
                    if incomingHandler is None:
                        return rEnv
                    if not incomingHandler(rEnv):
                        return None

            wsend, wrecv = fmap(TCPTransport._socketFile,
                                partition(TCPTransport._waitForSendable,
                                          filter(lambda T: not T.backoffPause(),
                                                 self._transmitIntents.values())))

            wrecv = [ s for s in wrecv if s ]
            wsend = [ s for s in wsend if s ]
            wrecv.extend([ I for I in self._incomingSockets if I and
                                   not self._incomingSockets[I].backoffPause()])
            if hasattr(self, '_openSockets'):
                wrecv.extend(list(map(lambda s: s.socket.fileno(),
                                      self._openSockets.values())))


            delays = list([R for R in [self.run_time.remaining()] +
                           [self._transmitIntents[T].delay() for T in self._transmitIntents] +
                           [W.delay() for W in self._waitingTransmits] +
                           [self._incomingSockets[I].delay() for I in self._incomingSockets]
                           if R is not None])
            # n.b. if a long period of time has elapsed (e.g. laptop sleeping) then delays
            # could be negative.
            delay = max(0, timePeriodSeconds(min(delays))) if delays else None

            if not hasattr(self, '_aborting_run') and not xmitOnly:
                wrecv.extend([self.socket.fileno()])
            else:
                # Windows does not support calling select with three
                # empty lists, so as a workaround, supply the main
                # listener if everything else is pending delays (or
                # completed but unrealized) here, and ensure the main
                # listener does not accept any listens below.
                if not wrecv and not wsend:
                    wrecv.extend([self.socket.fileno()])

            if self._watches:
                wrecv.extend(self._watches)

            try:
                rrecv, rsend, rerr = select.select(wrecv, wsend, set(wsend+wrecv), delay)
            except ValueError as ex:
                thesplog('ValueError on select(#%d: %s, #%d: %s, #%d: %s, %s)',
                         len(wrecv), wrecv, len(wsend), wsend,
                         len(set(wsend + wrecv)), set(wsend + wrecv),
                         delay, level=logging.ERROR)
                raise
            except select.error as ex:
                if err_select_retry(ex.args[0]): # errno.EINVAL is probably a change in descriptors
                    thesplog('select retry on %s', ex, level=logging.ERROR)
                    continue
                if err_bad_fileno(ex.args[0]):
                    # One of the selected file descriptors was bad,
                    # but no indication which one.  It should not be
                    # one of the ones locally managed by this
                    # transport, so it's likely one of the
                    # user-supplied "watched" file descriptors.  Find
                    # and remove it, then carry on.
                    if ex.errno == errno.EBADF:
                        bad = []
                        for each in self._watches:
                            try:
                                _ = select.select([each], [], [], 0)
                            except:
                                bad.append(each)
                        if not bad:
                            thesplog('bad internal file descriptor!')
                        else:
                            self._watches = [W for W in self._watches if W not in bad]
                            continue
                raise


            if rerr:
                for errfileno in rerr:
                    self._cancel_fd_ops(errfileno)

            origPendingSends = len(self._transmitIntents) + len(self._waitingTransmits)

            # Handle newly sendable data
            for eachs in rsend:
                self._processIntents(eachs)

            # Handle newly receivable data
            for each in rrecv:
                # n.b. ignore this if trying to quiesce; may have had
                # to supply this fd to avoid calling select with three
                # empty lists.
                if each == self.socket.fileno() and not hasattr(self, '_aborting_run') and not xmitOnly:
                    self._acceptNewIncoming()
                    continue
                # Get idleSockets before checking incoming and
                # transmit; those latter may modify _openSockets
                # (including replacing the element) so ensure that
                # only the sockets indicated by select are processed,
                # and only once each.
                idleSockets = list(getattr(self, '_openSockets', {}).items())

                if each in self._incomingSockets:
                    incoming = self._incomingSockets[each]
                    del self._incomingSockets[each]
                    incoming = self._handlePossibleIncoming(incoming, each)
                    if incoming:
                        self._incomingSockets[incoming.socket.fileno()] = incoming
                    continue

                if self._processIntents(each):
                    continue

                for rmtaddr,idle in idleSockets:
                    curOpen = self._openSockets.get(rmtaddr, None)
                    if curOpen and curOpen != idle:
                        # duplicate sockets to remote, and this one is
                        # no longer tracked, so close it and keep
                        # existing openSocket.
                        _safeSocketShutdown(idle.socket)
                    else:
                        if each == idle.socket.fileno():
                            del self._openSockets[rmtaddr]
                            incoming = self._handlePossibleIncoming(
                                TCPIncomingPersistent(rmtaddr, idle.socket), each)
                            if incoming:
                                self._incomingSockets[incoming.socket.fileno()] = incoming
                        elif idle.expired():
                            _safeSocketShutdown(idle.socket)
                            del self._openSockets[rmtaddr]

            # Handle timeouts
            self._processIntentTimeouts()
            rmvIncoming = []
            for I in self._incomingSockets:
                newI = self._handlePossibleIncoming(self._incomingSockets[I], -1)
                if newI:
                    # newI will possibly be new incoming data, but
                    # it's going to use the same socket
                    self._incomingSockets[I] = newI
                else:
                    rmvIncoming.append(I)
            for I in rmvIncoming:
                del self._incomingSockets[I]

            watchready = [W for W in self._watches if W in rrecv]
            if watchready:
                self._incomingEnvelopes.append(
                    ReceiveEnvelope(self.myAddress, WatchMessage(watchready)))

            # Check if it's time to quit
            if [] == rrecv and [] == rsend:
                if [] == rerr and self.run_time.expired():
                    # Timeout, give up
                    return None
                continue
            if xmitOnly:
                remXmits = len(self._transmitIntents) + len(self._waitingTransmits)
                if remXmits > origPendingSends or remXmits == 0:
                    return remXmits

            # Handle queued internal "received" data
            if not xmitOnly:
                while self._incomingEnvelopes:
                    rEnv = self._incomingEnvelopes.pop(0)
                    if incomingHandler is None:
                        return rEnv
                    if not incomingHandler(rEnv):
                        return None

        return None
dataset/ETHPy150Open godaddy/Thespian/thespian/system/transport/TCPTransport.py/TCPTransport._runWithExpiry/swapped operands of `>`