wait_for_prepare_to_finish

        :param prepare_id: MLPrepare.id to wait on
        :param sec_to_sleep: seconds to sleep during polling
        :param max_retries: max retires until stopping
506405
def wait_for_prepare_to_finish(
            self,
            prepare_id,
            sec_to_sleep=5.0,
            max_retries=100000):
        

        not_done = True
        retry_attempt = 1
        while not_done:

            if self.debug:
                log.info(("PREPSTATUS getting prepare.id={} details")
                         .format(
                            prepare_id))

            response = self.get_prepare_by_id(prepare_id)

            if self.debug:
                log.info(("PREPSTATUS got prepare.id={} response={}")
                         .format(
                            prepare_id,
                            response))

            if response["status"] != SUCCESS:
                log.error(("PREPSTATUS failed to get prepare.id={} "
                           "with error={}")
                          .format(
                            prepare_id,
                            response["error"]))
                return self.build_response(
                    status=ERROR,
                    error=response["error"],
                    data=response["data"])
            # stop if this failed getting the prepare details

            prepare_data = response.get(
                "data",
                None)

            if not prepare_data:
                return self.build_response(
                    status=ERROR,
                    error="failed to find prepare dictionary in response",
                    data=response["data"])

            prepare_status = prepare_data["status"]

            if prepare_status == "finished" \
               or prepare_status == "completed":

                not_done = False
                return self.build_response(
                    status=SUCCESS,
                    error="",
                    data=prepare_data)
            else:

                retry_attempt += 1
                if retry_attempt > max_retries:
                    err_msg = ("failed waiting "
                               "for prepare.id={} to finish").format(
                                   prepare_id)
                    log.error(err_msg)
                    return self.build_response(
                        status=ERROR,
                        error=err_msg)
                else:
                    if self.verbose:
                        if retry_attempt % 100 == 0:
                            log.info(("waiting on prepare.id={} retry={}")
                                     .format(
                                        prepare_id,
                                        retry_attempt))
                    # if logging just to show this is running
                    time.sleep(sec_to_sleep)
1234396
def _wait_for_process(self, p, shell=False):
        
        local_maxmem = -1
        sleeptime = .5
        while p.poll() is None:
            if not shell:
                local_maxmem = max(local_maxmem, self._memory_usage(p.pid) / 1e6)
                # print("int.maxmem (pid:" + str(p.pid) + ") " + str(local_maxmem))
            time.sleep(sleeptime)
            sleeptime = min(sleeptime + 5, 60)

        self.peak_memory = max(self.peak_memory, local_maxmem)
        
        del self.procs[p.pid]

        info = "Process " + str(p.pid) + " returned: (" + str(p.returncode) + ")."
        if not shell:
            info += " Peak memory: (Process: " + str(round(local_maxmem, 3)) + "GB;"
            info += " Pipeline: " + str(round(self.peak_memory, 3)) + "GB)\n"

        print(info + "\n")
        if p.returncode != 0:
            raise Exception("Process returned nonzero result.")
        return [p.returncode, local_maxmem]
919864
def retry_until_not_none_or_limit_reached(method, limit, sleep_s=1,
                                          catch_exceptions=()):
  """"""
  return retry_until_valid_or_limit_reached(
      method, limit, lambda x: x is not None, sleep_s, catch_exceptions)
1295822
def _wait(jid):
    '''
    
    '''
    if jid is None:
        jid = salt.utils.jid.gen_jid(__opts__)
    states = _prior_running_states(jid)
    while states:
        time.sleep(1)
        states = _prior_running_states(jid)
62531
def wait_until_state(task_id, state, max_nap)
      blink_time = 5 # wake up and scan
      nap_start = Time.now
      state_method = method("task_#{state}?".to_sym)
      loop do
        break if state_method.call(task_id)
        raise TaskNotDoneError, "Task: #{task_id} has taken too long to complete!" if Time.new > (nap_start + max_nap)

        sleep blink_time
      end
      task_id
    end
565893
def incrementing_sleep(self, previous_attempt_number, delay_since_first_attempt_ms):
        
        result = self._wait_incrementing_start + (self._wait_incrementing_increment * (previous_attempt_number - 1))
        if result < 0:
            result = 0
        return result
784748
def _init_polling(self):
        
        with self.lock:
            if not self.running:
                return

            r = random.Random()
            delay = r.random() * self.refresh_interval
            self.channel.io_loop.call_later(
                delay=delay, callback=self._delayed_polling)
            self.logger.info(
                'Delaying throttling credit polling by %d sec', delay)
1318894
public void waitForLock(T jedis){
        while(!lock(jedis)){
            try {
                logger.debug("Waiting for Redis lock.");
                Thread.sleep(randomInt(75, 125));
            } catch (InterruptedException e) {
                logger.error("Interrupted while waiting for lock.", e);
            }
        }
    }
1365528
def wait(*args, **kwargs):
    
    kwargs.setdefault('sleep_seconds', (1, None))
    kwargs.setdefault('expected_exceptions', WebDriverException)
    kwargs.setdefault('timeout_seconds', webium.settings.wait_timeout)

    return wait_lib(*args, **kwargs)
167843
private void doWait( int currentTries, long optDuration_ms )
    {
        if ( optDuration_ms < 0 ) {
            optDuration_ms = ( long ) ( firstSleep_ms * ( Math.random() + 0.5 ) * ( 1L << ( currentTries - 1 ) ) );
        }

        LOGGER.debug( "Will retry request after {} millis", optDuration_ms );

        try {
            Thread.sleep( optDuration_ms );
        } catch ( InterruptedException ex ) {
            throw new CStorageException( "Retry waiting interrupted", ex );
        }
    }
1030317
def _wait_for_machine_finish(self, name):
        
        # TODO: rewrite it using probes module in utils
        for foo in range(constants.DEFAULT_RETRYTIMEOUT):
            time.sleep(constants.DEFAULT_SLEEP)
            out = run_cmd(
                ["machinectl", "--no-pager", "status", name],
                ignore_status=True, return_output=True)
            if out != 0:
                return True
        raise ConuException(
            "Unable to stop machine %s within %d" %
            (name, constants.DEFAULT_RETRYTIMEOUT))
1245442
def wait(timeout = SimCtl.default_timeout)
      Timeout.timeout(timeout) do
        loop do
          break if yield SimCtl.device(udid: udid)
        end
      end
      reload
    end
670101
def _wait_for_completion(conn, wait_timeout, server_id):
    '''
    
    '''
    wait_timeout = time.time() + wait_timeout
    while wait_timeout > time.time():
        time.sleep(5)

        server = conn.get_server(server_id)
        server_state = server['status']['state'].lower()

        if server_state == "powered_on":
            return
        elif server_state == 'failed':
            raise Exception('Server creation failed for {0}'.format(server_id))
        elif server_state in ('active',
                              'enabled',
                              'deploying',
                              'configuring'):
            continue
        else:
            raise Exception(
                'Unknown server state {0}'.format(server_state))
    raise Exception(
        'Timed out waiting for server create completion for {0}'.format(server_id)
    )
939068
def sleep_and_retry(func):
    '''
    
    '''
    @wraps(func)
    def wrapper(*args, **kargs):
        '''
        Call the rate limited function. If the function raises a rate limit
        exception sleep for the remaing time period and retry the function.

        :param args: non-keyword variable length argument list to the decorated function.
        :param kargs: keyworded variable length argument list to the decorated function.
        '''
        while True:
            try:
                return func(*args, **kargs)
            except RateLimitException as exception:
                time.sleep(exception.period_remaining)
    return wrapper
408009
def wait(self, timeout=None):
        """"""
        logger = logging.getLogger(__name__)
        if int(self.max_sleep_interval) < int(self._min_sleep_interval):
            self.max_sleep_interval = int(self._min_sleep_interval)
        t0 = time.time()
        sleep_seconds = min(5, self.max_sleep_interval)
        status = self.status
        prev_status = status
        while status < COMPLETED:
            logger.debug("sleep for %d seconds", sleep_seconds)
            time.sleep(sleep_seconds)
            if 2*sleep_seconds <= self.max_sleep_interval:
                sleep_seconds *= 2
            if timeout is not None:
                if int(time.time() - t0) > int(timeout):
                    return
            status = self.status
            if status != prev_status:
                sleep_seconds = min(5, self.max_sleep_interval)
                prev_status = status
993677
private void scheduleRetryFuture() {
        Log.v(Log.TAG_SYNC, "%s: Failed to xfer; will retry in %d sec", this, RETRY_DELAY_SECONDS);
        synchronized (executor) {
            if (!executor.isShutdown()) {
                this.retryFuture = executor.schedule(new Runnable() {
                    public void run() {
                        retryIfReady();
                    }
                }, RETRY_DELAY_SECONDS, TimeUnit.SECONDS);
            }
        }
    }
518095
def wait(self, seconds, poll_interval):
        
        # jid is None when all hosts were skipped
        if self.jid is None:
            return self.results

        clock = seconds - poll_interval
        while (clock >= 0 and not self.completed):
            time.sleep(poll_interval)

            poll_results = self.poll()

            for (host, res) in poll_results['polled'].iteritems():
                if res.get('started'):
                    self.runner.callbacks.on_async_poll(host, res, self.jid, clock)

            clock = clock - poll_interval

        return self.results