Returns an event or None if no events occur before timeout.
519599
def send(self, timeout=None):
        """"""
        if self.sigint_event and is_main_thread():
            with ReplacedSigIntHandler(self.sigint_handler):
                return self._send(timeout)
        else:
            return self._send(timeout)
516015
def get(self, timeout=None, block=True):
        
        return self.get_event(timeout, block).data
1116337
def get_timeout(self, callback=None):
        
        def got_timeout(a):
            if callable(callback):
                callback(int(a['VisibilityTimeout']))
        self.get_attributes('VisibilityTimeout', callback=got_timeout)
782006
def _on_timeout(self, info: str = None) -> None:
        
        self._timeout = None
        error_message = "Timeout {0}".format(info) if info else "Timeout"
        if self.final_callback is not None:
            self._handle_exception(
                HTTPTimeoutError, HTTPTimeoutError(error_message), None
            )
451538
def wait(self, timeout):
    

    with self._condition:
      previous_iteration = self._iteration
      self._condition.wait(timeout)
      return previous_iteration != self._iteration
217886
def _wait_for_io_events(socks, events, timeout=None):
    
    if not HAS_SELECT:
        raise ValueError('Platform does not have a selector')
    if not isinstance(socks, list):
        # Probably just a single socket.
        if hasattr(socks, "fileno"):
            socks = [socks]
        # Otherwise it might be a non-list iterable.
        else:
            socks = list(socks)
    with DefaultSelector() as selector:
        for sock in socks:
            selector.register(sock, events)
        return [key[0].fileobj for key in
                selector.select(timeout) if key[1] & events]
435726
def get_event(self, event_key):
    

    event = self.event_key_map.get(event_key)

    if event:
      return event

    self.logger.error('Event "%s" is not in datafile.' % event_key)
    self.error_handler.handle_error(exceptions.InvalidEventException(enums.Errors.INVALID_EVENT_KEY_ERROR))
    return None
459176
def PopEvent(self):
    
    try:
      _, _, _, event = heapq.heappop(self._heap)
      return event

    except IndexError:
      return None
417530
def _do_wait(self, timeout):
        

        if self._cancelled:
            raise CancelledError()

        if not self._done:
            self._wait = True
            
            self._sigint = pyev.Signal(signal.SIGINT, self.loop, lambda watcher, events: self._cancel(), None)
            self._sigint.start()

            if timeout and timeout > 0.0:
                self._timer = pyev.Timer(timeout, 0.0, self.loop,
                                         self._clear_wait, None)
                self._timer.start()

            while self._wait and not self._done and not self._cancelled:
                self.loop.start(pyev.EVRUN_ONCE)

        if self._cancelled:
            raise CancelledError()
        elif not self._done:
            raise TimeoutError()
858561
def _wait_signal(signal, timeout=None):
    """"""
    # http://jdreaver.com/posts/2014-07-03-waiting-for-signals-pyside-pyqt.html
    loop = QEventLoop()
    signal.connect(loop.quit)

    yield

    if timeout is not None:
        QTimer.singleShot(timeout, loop.quit)
    loop.exec_()
1221041
def _wait_and_except_if_failed(self, event, timeout=None):
        
        event.wait(timeout or self.__sync_timeout)
        self._except_if_failed(event)
921678
def _get_timeout(self, timeout):
        
        if timeout is _Default:
            return self.timeout.clone()

        if isinstance(timeout, Timeout):
            return timeout.clone()
        else:
            # User passed us an int/float. This is for backwards compatibility,
            # can be removed later
            return Timeout.from_float(timeout)
822656
private void waitForEventOrTimeout() throws InterruptedException {
        long remainingWait = timeout - timeWaited;
        long millisToWait = remainingWait / 1000000;
        int nanosToWait = (int) (remainingWait % 1000000);
        wait(millisToWait, nanosToWait);
    }
759668
def timeout_deferred(deferred, timeout, error_message="Timeout occured"):
    
    
    timeout_occured = [False]
    
    def got_result(result):
        if not timeout_occured[0]:
            # Deferred called back before the timeout.
            delayedCall.cancel()
            return result
        else:
            if isinstance(result, failure.Failure) and result.check(defer.CancelledError):
                # Got a `CancelledError` after we called  `cancel()`.
                # Replace it with a `TimeoutError`.
                raise TimeoutError(error_message)
            else:
                # Apparently the given deferred has something else to tell us.
                # It might be that it completed before the `cancel()` had an effect
                # (or as a result thereof). It might also be that it triggered an
                # error. In either case, we want this to be visible down-stream.
                return result
    
    def time_is_up():
        timeout_occured[0] = True
        deferred.cancel()
    delayedCall = reactor.callLater(timeout, time_is_up)

    deferred.addBoth(got_result)
    return deferred
837858
def wait_until_gone(self, timeout=0, *args, **selectors):
        
        return self.device(**selectors).wait.gone(timeout=timeout)
1157928
def exception(self, timeout=None, do_raise=True):
    

    with self._lock:
      self.wait(timeout, do_raise=do_raise)
      if not self._exc_info:
        return None
      self._exc_retrieved = True
      if self._cancelled:
        raise self.Cancelled()
      return self._exc_info[1]
48996
def _handle(self, event_handler, event_name, user_args, event_timeout,
                cond, cond_timeout):
        
        if cond:
            cond.wait(cond_timeout)
        event = self.pop_event(event_name, event_timeout)
        return event_handler(event, *user_args)