Helper function for testing non-blocking mode.

    This function blocks the calling thread for <timeout> seconds -
    to be used only for testing purposes.

    Also available at `ssh2.utils.wait_socket`
491074
def wait_socket(_socket, session, timeout=1):
    
    directions = session.block_directions()
    if directions == 0:
        return 0
    readfds = [_socket] \
        if (directions & LIBSSH2_SESSION_BLOCK_INBOUND) else ()
    writefds = [_socket] \
        if (directions & LIBSSH2_SESSION_BLOCK_OUTBOUND) else ()
    return select(readfds, writefds, (), timeout)
370387
def select_sockets(self, timeout=None):
        
        if timeout is not None:
            t = time.time()
        while True:
            try:
                ready, __, __ = select.select(self.sockets(), (), (), timeout)
            except ValueError:
                # there's fd=0 socket.
                pass
            except select.error as exc:
                # ignore an interrupted system call.
                if exc.args[0] != EINTR:
                    raise
            else:
                # succeeded.
                return ready
            # retry.
            if timeout is None:
                continue
            # decrease timeout.
            t2 = time.time()
            timeout -= t2 - t
            t = t2
            if timeout <= 0:
                # timed out.
                return []
56940
def aiohttp_socket_timeout(socket_timeout_s):
  
  return aiohttp.ClientTimeout(total=None,
                               connect=None,
                               sock_connect=socket_timeout_s,
                               sock_read=socket_timeout_s)
290894
def _get_socket_no_auth(self):
        """"""
        # We use the pid here to avoid issues with fork / multiprocessing.
        # See test.test_client:TestClient.test_fork for an example of
        # what could go wrong otherwise
        if self.pid != os.getpid():
            self.reset()

        # Get a free socket or create one.
        if not self._socket_semaphore.acquire(
                True, self.opts.wait_queue_timeout):
            self._raise_wait_queue_timeout()
        with self.lock:
            self.active_sockets += 1

        # We've now acquired the semaphore and must release it on error.
        try:
            try:
                # set.pop() isn't atomic in Jython less than 2.7, see
                # http://bugs.jython.org/issue1854
                with self.lock:
                    # Can raise ConnectionFailure.
                    sock_info = self.sockets.popleft()
            except IndexError:
                # Can raise ConnectionFailure or CertificateError.
                sock_info = self.connect()
            else:
                # Can raise ConnectionFailure.
                sock_info = self._check(sock_info)
        except Exception:
            self._socket_semaphore.release()
            with self.lock:
                self.active_sockets -= 1
            raise

        return sock_info
1085498
def wait_until time_to_wait=30, &block
      time_limit = Time.now + time_to_wait
      until block.call 
        if Time.now > time_limit
          raise "wait_until timeout after #{time_to_wait} seconds"
        end
        sleep 0.1
      end
      true
    end
922718
def wait(self, timeout=None):
        
        try:
            if timeout:
                gevent.sleep(timeout)
            else:
                while True:
                    gevent.sleep(1000)
        except (KeyboardInterrupt, SystemExit, Exception):
            pass
960052
def wait_for(func):
    

    @wraps(func)
    def wrapped(*args, **kwargs):
        timeout = kwargs.pop('timeout', TIMEOUT)

        start = None

        while True:
            try:
                return func(*args, **kwargs)
            except AssertionError:
                # The function took some time to test the assertion, however,
                # the result might correspond to the state of the world at any
                # point in time, perhaps earlier than the timeout. Therefore,
                # start counting time from the first assertion fail, not from
                # before the function was called.
                if not start:
                    start = time()
                if time() - start < timeout:
                    sleep(CHECK_EVERY)
                    continue
                else:
                    raise

    return wrapped
93185
def wait(self, timeout):
        
        self.timeout = timeout
        self.start()
        self.join(timeout=5)
45648
def _handle_force_timeout(self) -> None:
        
        while True:
            try:
                ret, num_handles = self._multi.socket_all()
            except pycurl.error as e:
                ret = e.args[0]
            if ret != pycurl.E_CALL_MULTI_PERFORM:
                break
        self._finish_pending_requests()
37399
def wait(mutex, timeout = nil)
      start_time = Garcon.monotonic_time
      @condition.wait(mutex, timeout)

      if timeout.nil?
        Result.new(nil)
      else
        Result.new(start_time + timeout - Garcon.monotonic_time)
      end
    end
54054
def WaitUntilNoFlowsToProcess(self, timeout=None):
    
    t = self.flow_handler_thread
    if not t:
      return

    start_time = time.time()
    while True:
      with self.lock:
        # If the thread is dead, or there are no requests
        # to be processed/being processed, we stop waiting
        # and return from the function.
        if (not t.isAlive() or
            (not self._GetFlowRequestsReadyForProcessing() and
             not self.flow_handler_num_being_processed)):
          return

      time.sleep(0.2)

      if timeout and time.time() - start_time > timeout:
        raise TimeOutWhileWaitingForFlowsToBeProcessedError(
            "Flow processing didn't finish in time.")
659176
def _blocking_pop(self, pop_func, keys, timeout):
        """"""
        if not isinstance(timeout, (int, long)):
            raise RuntimeError('timeout is not an integer or out of range')

        if timeout is None or timeout == 0:
            timeout = self.blocking_timeout

        if isinstance(keys, basestring):
            keys = [keys]
        else:
            keys = list(keys)

        elapsed_time = 0
        start = time.time()
        while elapsed_time < timeout:
            key, val = self._pop_first_available(pop_func, keys)
            if val:
                return key, val
            # small delay to avoid high cpu utilization
            time.sleep(self.blocking_sleep_interval)
            elapsed_time = time.time() - start
        return None
53067
public long waitForZkTxId(long zkTxId, Object timeout)
    throws TimeoutException, InterruptedException
  {
    long endTime = ClockUtils.toEndTime(clock, timeout);

    synchronized(_lock)
    {
      while(_lastZkTxId < zkTxId)
      {
        ConcurrentUtils.awaitUntil(clock, _lock, endTime);
      }

      return _lastZkTxId;
    }
  }
496266
def _wait(self, timeout=None):
        
        r, w, x = select.select([self._stick_file], [], [], timeout)
        return bool(r)
1086518
def wait(self, timeout=None):
        

        if timeout is not None:
            if not self._thread:
                self._thread = threading.Thread(target=self._wait4process)
                self._thread.daemon = 1
                self._thread.start()

        if self._thread:
            self._thread.join(timeout=timeout)
            self.timeout_happened = self.timeout_happened or self._thread.isAlive()
        else:
            # no timeout and no existing thread
            self._wait4process()

        return self
180938
public final T blockResult(long timeout) throws TError, CancelException {
		Thread t;
		BlockedThreadHandler blockedHandler;
		synchronized (this) {
			if (unblocked && listenersInline == null) {
				if (error != null) throw error;
				if (cancel != null) throw cancel;
				return result;
			}
			t = Thread.currentThread();
			blockedHandler = Threading.getBlockedThreadHandler(t);
			if (blockedHandler == null)
				while (!unblocked || listenersInline != null)
					try { this.wait(timeout < 0 ? 0 : timeout); }
					catch (InterruptedException e) { return null; }
		}
		if (blockedHandler != null)
			blockedHandler.blocked(this, timeout);
		if (error != null) throw error;
		if (cancel != null) throw cancel;
		return result;
	}
416796
static <V extends VersionedProtocol> V waitForProxy(Class<V> protocol, InetSocketAddress addr,
			long timeout) throws IOException {
		long startTime = System.currentTimeMillis();
		IOException ioe;
		while (true) {
			try {
				return getProxy(protocol, addr);
			} catch (ConnectException se) { // namenode has not been started
				LOG.info("Server at " + addr + " not available yet, Zzzzz...");
				ioe = se;
			} catch (SocketTimeoutException te) { // namenode is busy
				LOG.info("Problem connecting to server: " + addr);
				ioe = te;
			}
			// check if timed out
			if (System.currentTimeMillis() - timeout >= startTime) {
				throw ioe;
			}

			// wait for retry
			try {
				Thread.sleep(1000);
			} catch (InterruptedException ie) {
				// IGNORE
			}
		}
	}