Body#sleepCheck( [dt] )
- dt (Number): Time to advance the idle time

Check if the body should be sleeping.

Call with no arguments if some event could possibly wake up the body. This will force the body to recheck.
344220
function( dt ){

            var opts = this._world && this._world.options;

            // if sleeping disabled. stop.
            if ( this.sleepDisabled || (opts && opts.sleepDisabled) ){
                return;
            }

            var limit
                ,v
                ,d
                ,r
                ,aabb
                ,scratch = Physics.scratchpad()
                ,diff = scratch.vector()
                ,diff2 = scratch.vector()
                ,kfac
                ,stats
                ;

            dt = dt || 0;
            aabb = this.geometry.aabb();
            r = Math.max(aabb.hw, aabb.hh);

            if ( this.asleep ){
                // check velocity
                v = this.state.vel.norm() + Math.abs(r * this.state.angular.vel);
                limit = this.sleepSpeedLimit || (opts && opts.sleepSpeedLimit) || 0;

                if ( v >= limit ){
                    this.sleep( false );
                    return scratch.done();
                }
            }

            this._sleepMeanK++;
            kfac = this._sleepMeanK > 1 ? 1/(this._sleepMeanK - 1) : 0;
            Physics.statistics.pushRunningVectorAvg( this.state.pos, this._sleepMeanK, this._sleepPosMean, this._sleepPosVariance );
            // we take the sin because that maps the discontinuous angle to a continuous value
            // then the statistics calculations work better
            stats = Physics.statistics.pushRunningAvg( Math.sin(this.state.angular.pos), this._sleepMeanK, this._sleepAngPosMean, this._sleepAngPosVariance );
            this._sleepAngPosMean = stats[0];
            this._sleepAngPosVariance = stats[1];
            v = this._sleepPosVariance.norm() + Math.abs(r * Math.asin(stats[1]));
            v *= kfac;
            limit = this.sleepVarianceLimit || (opts && opts.sleepVarianceLimit) || 0;
            // console.log(v, limit, kfac, this._sleepPosVariance.norm(), stats[1])
            if ( v <= limit ){
                // check idle time
                limit = this.sleepTimeLimit || (opts && opts.sleepTimeLimit) || 0;
                this.sleepIdleTime = (this.sleepIdleTime || 0) + dt;

                if ( this.sleepIdleTime > limit ){
                    this.asleep = true;
                }
            } else {
                this.sleep( false );
            }

            scratch.done();
        }
979406
private void checkJodaSetGetHour() {
        int COUNT = COUNT_VERY_FAST;
        // Is it fair to use only MutableDateTime here? You decide.
        MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
        for (int i = 0; i < AVERAGE; i++) {
            start("Joda", "setGetHour");
            for (int j = 0; j < COUNT; j++) {
                dt.setHourOfDay(13);
                int val = dt.getHourOfDay();
                if (dt == null) {System.out.println("Anti optimise");}
            }
            end(COUNT);
        }
    }
1357047
def debug_sleep(self, timeout):
        """"""
        fut = self.execute(b'DEBUG', b'SLEEP', timeout)
        return wait_ok(fut)
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
585083
public void setCheckInterval(long checkInterval)
  {
    if (checkInterval < 0 || checkInterval > Long.MAX_VALUE / 2)
      _checkInterval = Long.MAX_VALUE / 2;
    else
      _checkInterval = checkInterval;

    _checkExpiresTime = 0;
  }
452214
def check(self):
    

    if self.value is None:
      return False
    return (time.clock() - self.start) >= self.value
760966
def sleep(self, seconds):
        
        start = self.time()
        while (self.time() - start < seconds and
               not self.need_to_stop.is_set()):
            self.need_to_stop.wait(self.sim_time)
666161
def sleep(self, time):
        
        target = 'wait for %s' % str(time)
        self.device(text=target).wait.exists(timeout=time)
486947
def _WaitForStatusNotRunning(self):
    """"""
    # We wait slightly longer than the status check sleep time.
    time.sleep(2.0)
    time_slept = 2.0
    while self._status_is_running:
      time.sleep(0.5)
      time_slept += 0.5
      if time_slept >= self._PROCESS_JOIN_TIMEOUT:
        break
593777
def interruptible_sleep(t, event=None):
    
    log.info("sleeping %s", t)

    if event is None:
        time.sleep(t)
        return False
    else:
        return not event.wait(t)
68003
def _wait(starting_time, first_timestamp, timestamp):
        
        target_time = starting_time + (timestamp - first_timestamp)
        time.sleep(max(target_time - time.time(), 0))
83886
def check(self, check_url=None):
        

        if check_url is not None:
            self.check_url = self._normalize_check_url(check_url)

        response = None
        sleeped = 0.0
        t = datetime.now()

        while not response:
            try:
                response = requests.get(self.check_url, verify=False)
            except requests.exceptions.ConnectionError:
                if sleeped > self.timeout:
                    self._kill()
                    raise LiveAndLetDieError(
                        '{0} server {1} didn\'t start in specified timeout {2} '
                        'seconds!\ncommand: {3}'.format(
                            self.__class__.__name__,
                            self.check_url,
                            self.timeout,
                            ' '.join(self.create_command())
                        )
                    )
                time.sleep(1)
                sleeped = _get_total_seconds(datetime.now() - t)

        return _get_total_seconds(datetime.now() - t)
275511
async def _continueAfterSleep(self, seconds):
        
        assert self._sleeping is None
        self._sleeping = InterruptibleSleep(seconds)
        try:
            await self._sleeping.wait()
            return True
        except asyncio.CancelledError:
            return not self._is_stopping
        finally:
            self._sleeping = None
1234477
def check_time(self):
        

        poll = self.config['timecheck']['poll']
        ntp_poll = self.config['timecheck']['ntp_pool']
        while True:
            clnt = ntplib.NTPClient()
            try:
                response = clnt.request(ntp_poll, version=3)
                diff = response.offset
                if abs(diff) >= 15:
                    logger.error('Timings found to be far off, shutting down drone ({0})'.format(diff))
                    sys.exit(1)
                else:
                    logger.debug('Polled ntp server and found that drone has {0} seconds offset.'.format(diff))
            except (ntplib.NTPException, _socket.error) as ex:
                logger.warning('Error while polling ntp server: {0}'.format(ex))
            gevent.sleep(poll * 60 * 60)
121042
def log_random_sleep(self, minimum=3.0, scale=1.0, hints=None):
        
        hints = '{} slept'.format(hints) if hints else 'slept'
        st = time.time()
        helper.random_sleep(minimum, scale)
        log.debug('{} {} {}s'.format(
            self.symbols.get('sleep', ''), hints, self.color_log(time.time() - st)))
61838
public void setCheckInterval(long checkInterval)
  {
    if (checkInterval < 0 || checkInterval > Long.MAX_VALUE / 2)
      _checkInterval = Long.MAX_VALUE / 2;
    else
      _checkInterval = checkInterval;

    _lastCheckTime = 0;
  }
1027266
def clock(seg, seconds):
    
    interval = 0.5
    for i in range(int(seconds / interval)):
        now = datetime.now()
        seg.text = now.strftime("%H-%M-%S")

        # calculate blinking dot
        if i % 2 == 0:
            seg.text = now.strftime("%H-%M-%S")
        else:
            seg.text = now.strftime("%H %M %S")

        time.sleep(interval)