prevent the main loop spinning too fast
494454
def on_idle(self, event):
        ''''''
        state = self.state

        if state.close_window.acquire(False):
            self.state.app.ExitMainLoop()

        # receive any display objects from the parent
        obj = None

        while not state.object_queue.empty():
            obj = state.object_queue.get()

            if isinstance(obj, SlipObject):
                self.add_object(obj)

            if isinstance(obj, SlipPosition):
                # move an object
                object = self.find_object(obj.key, obj.layer)
                if object is not None:
                    object.update_position(obj)
                    if getattr(object, 'follow', False):
                        self.follow(object)
                    state.need_redraw = True

            if isinstance(obj, SlipDefaultPopup):
                state.default_popup = obj

            if isinstance(obj, SlipInformation):
                # see if its a existing one or a new one
                if obj.key in state.info:
#                    print('update %s' % str(obj.key))
                    state.info[obj.key].update(obj)
                else:
#                    print('add %s' % str(obj.key))
                    state.info[obj.key] = obj
                state.need_redraw = True

            if isinstance(obj, SlipCenter):
                # move center
                (lat,lon) = obj.latlon
                state.panel.re_center(state.width/2, state.height/2, lat, lon)
                state.need_redraw = True

            if isinstance(obj, SlipBrightness):
                # set map brightness
                state.brightness = obj.brightness
                state.need_redraw = True

            if isinstance(obj, SlipClearLayer):
                # remove all objects from a layer
                if obj.layer in state.layers:
                    state.layers.pop(obj.layer)
                state.need_redraw = True

            if isinstance(obj, SlipRemoveObject):
                # remove an object by key
                for layer in state.layers:
                    if obj.key in state.layers[layer]:
                        state.layers[layer].pop(obj.key)
                state.need_redraw = True

            if isinstance(obj, SlipHideObject):
                # hide an object by key
                for layer in state.layers:
                    if obj.key in state.layers[layer]:
                        state.layers[layer][obj.key].set_hidden(obj.hide)
                state.need_redraw = True
        
        if obj is None:
            time.sleep(0.05)
402274
def loop(self):
        
        logging.info("Running %s in loop mode." % self.service_name)

        res = None
        while True:
            try:
                res = self.run()
                time.sleep(self.loop_duration)
            except KeyboardInterrupt:
                logging.warning("Keyboard Interrupt during loop, stopping %s service now..." % self.service_name)
                break
            except Exception as e:
                logging.exception("Error in %s main loop! (%s)" % (self.service_name, e))
                raise e
        return res
348865
def _delay_for_ratelimits(cls, start):
        """"""
        stop = datetime.now()
        duration_microseconds = (stop - start).microseconds
        if duration_microseconds < cls.REQUEST_TIME_MICROSECONDS:
            time.sleep((cls.REQUEST_TIME_MICROSECONDS - duration_microseconds)
                       / MICROSECONDS_PER_SECOND)
1156042
public void checkForRotation() {
    try {
      BufferedReader probe = new BufferedReader(new FileReader(file.getAbsoluteFile()));
      if (firstLine == null || (!firstLine.equals(probe.readLine()))) {
	probe.close();
	// start reading the file from the beginning
        reader.close();
        reader = new BufferedReader(new FileReader(file.getAbsoluteFile()));
	firstLine = null;
	offset = 0;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
927964
def fast_exit(code):
    
    sys.stdout.flush()
    sys.stderr.flush()
    os._exit(code)
1113281
def _loop_thread_main(self):
        """"""

        asyncio.set_event_loop(self.loop)
        self._loop_check.inside_loop = True

        try:
            self._logger.debug("Starting loop in background thread")
            self.loop.run_forever()
            self._logger.debug("Finished loop in background thread")
        except:  # pylint:disable=bare-except;This is a background worker thread.
            self._logger.exception("Exception raised from event loop thread")
        finally:
            self.loop.close()
1179930
async def loop(self):
        """"""
        while not self.stopped:
            self.timeout_handle = self.pyvlx.connection.loop.call_later(
                self.timeout_in_seconds, self.loop_timeout)
            await self.loop_event.wait()
            if not self.stopped:
                self.loop_event.clear()
                await self.pulse()
        self.cancel_loop_timeout()
        self.stopped_event.set()
97888
private void maybeStop(long stopCheck, long now)
    {
        long delta = now - stopCheck;
        if (delta <= 0)
        {
            // if stopCheck has caught up with present, we've been spinning too much, so if we can atomically
            // set it to the past again, we should stop a worker
            if (pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval))
            {
                // try and stop ourselves;
                // if we've already been assigned work stop another worker
                if (!assign(Work.STOP_SIGNALLED, true))
                    pool.schedule(Work.STOP_SIGNALLED);
            }
        }
        else if (soleSpinnerSpinTime > stopCheckInterval && pool.spinningCount.get() == 1)
        {
            // permit self-stopping
            assign(Work.STOP_SIGNALLED, true);
        }
        else
        {
            // if stop check has gotten too far behind present, update it so new spins can affect it
            while (delta > stopCheckInterval * 2 && !pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval))
            {
                stopCheck = pool.stopCheck.get();
                delta = now - stopCheck;
            }
        }
    }
271729
def _main_loop(self):
        '''
        
        '''
        self.logger.debug("Running main loop")
        old_time = 0
        while True:
            for plugin_key in self.plugins_dict:
                obj = self.plugins_dict[plugin_key]
                self._process_plugin(obj)

            if self.settings['STATS_DUMP'] != 0:
                new_time = int(old_div(time.time(), self.settings['STATS_DUMP']))
                # only log every X seconds
                if new_time != old_time:
                    self._dump_stats()

                    if self.settings['STATS_DUMP_CRAWL']:
                        self._dump_crawl_stats()

                    if self.settings['STATS_DUMP_QUEUE']:
                        self._dump_queue_stats()

                    old_time = new_time
            self._report_self()
            time.sleep(self.settings['SLEEP_TIME'])
895500
def spin(self, start_message, end_message, fmt=None, interval=100, values=None):
        
        spinner = ProgressIndicator(self.io, fmt, interval, values)

        return spinner.auto(start_message, end_message)
258346
def halt(self):
        
        if self._callback:
            self._thread_continue = False
            self._thread.join()
826070
def right_stop(self):
        """"""
        self.board.digital_write(R_CTRL_1, 0)
        self.board.digital_write(R_CTRL_2, 0)
        self.board.analog_write(PWM_R, 0)
305800
function() {
    var self = this;
    // delay to make sure the spinner has a chance to spin for a split second before it's dismissed
    var d = new Date();
    var delay = 0;
    if (self.refreshStartTime + self.__minSpinTime > d.getTime()){
      delay = self.refreshStartTime + self.__minSpinTime - d.getTime();
    }
    setTimeout(function(){
      if (self.__refreshTail){
        self.__refreshTail();
      }
      setTimeout(function(){
        self.__refreshActive = false;
        if (self.__refreshDeactivate) {
          self.__refreshDeactivate();
        }
        if (self.__refreshHide){
          self.__refreshHide();
        }

        self.scrollTo(self.__scrollLeft, self.__scrollTop, true);
      },self.__refreshTailTime);
    },delay);
  }
226300
def _freeze(self, final_text, err=False):
        """"""
        if not final_text:
            final_text = ""
        target = self.stderr if err else self.stdout
        if target.closed:
            target = sys.stderr if err else sys.stdout
        text = to_text(final_text)
        last_frame = self._compose_out(text, mode="last")
        self._last_frame = decode_output(last_frame, target_stream=target)

        # Should be stopped here, otherwise prints after
        # self._freeze call will mess up the spinner
        self.stop()
        target.write(self._last_frame)
867481
private static void disableSpinnerDragging(JSpinner spinner)
    {
        int n = spinner.getComponentCount();
        for (int i=0; i<n; i++)
        {
            Component c = spinner.getComponent(i);
            String name = c.getName();
            if ("Spinner.nextButton".equals(name) ||
                "Spinner.previousButton".equals(name))
            {
                MouseMotionListener mouseMotionListeners[] =
                    c.getMouseMotionListeners();
                for (MouseMotionListener m : mouseMotionListeners)
                {
                    if (m instanceof SpinnerDraggingHandler)
                    {
                        c.removeMouseMotionListener(m);
                    }
                }
                MouseListener mouseListeners[] =
                    c.getMouseListeners();
                for (MouseListener m : mouseListeners)
                {
                    if (m instanceof SpinnerDraggingHandler)
                    {
                        c.removeMouseListener(m);
                    }
                }
            }
        }
    }
1370094
def keep_running(self):
        
        if self.runs >= self.max_runs:
            raise ExecutionRunsException(
                '{} run into barrier of {} iterations without '
                'finding the destination'.format(
                    self.__class__.__name__, self.max_runs))

        if time.time() - self.start_time >= self.time_limit:
            raise ExecutionTimeException(
                '{} took longer than {} seconds, aborting!'.format(
                    self.__class__.__name__, self.time_limit))
117300
def stop(self) -> None:
        """"""
        self._running = False
        if self._timeout is not None:
            self.io_loop.remove_timeout(self._timeout)
            self._timeout = None