Ported from:
        http://seattlerobotics.org/encoder/200610/Article3/IMU%20Odometry,%20by%20David%20Anderson.htm

        A thread is started that will run until the user calls odometry_stop()
        which will set odometry_thread_run to False
493220
def odometry_start(self, theta_degrees_start=90.0,
            x_pos_start=0.0, y_pos_start=0.0,
            SLEEP_TIME=0.005):  # 5ms
        

        def _odometry_monitor():
            left_previous = 0
            right_previous = 0
            self.theta = math.radians(theta_degrees_start)  # robot heading
            self.x_pos_mm = x_pos_start  # robot X position in mm
            self.y_pos_mm = y_pos_start  # robot Y position in mm
            TWO_PI = 2 * math.pi

            while self.odometry_thread_run:

                # sample the left and right encoder counts as close together
                # in time as possible
                left_current = self.left_motor.position
                right_current = self.right_motor.position

                # determine how many ticks since our last sampling
                left_ticks = left_current - left_previous
                right_ticks = right_current - right_previous

                # Have we moved?
                if not left_ticks and not right_ticks:
                    if SLEEP_TIME:
                        time.sleep(SLEEP_TIME)
                    continue

                # log.debug("%s: left_ticks %s (from %s to %s)" %
                #     (self, left_ticks, left_previous, left_current))
                # log.debug("%s: right_ticks %s (from %s to %s)" %
                #     (self, right_ticks, right_previous, right_current))

                # update _previous for next time
                left_previous = left_current
                right_previous = right_current

                # rotations = distance_mm/self.wheel.circumference_mm
                left_rotations = float(left_ticks / self.left_motor.count_per_rot)
                right_rotations = float(right_ticks / self.right_motor.count_per_rot)

                # convert longs to floats and ticks to mm
                left_mm = float(left_rotations * self.wheel.circumference_mm)
                right_mm = float(right_rotations * self.wheel.circumference_mm)

                # calculate distance we have traveled since last sampling
                mm = (left_mm + right_mm) / 2.0

                # accumulate total rotation around our center
                self.theta += (right_mm - left_mm) / self.wheel_distance_mm

                # and clip the rotation to plus or minus 360 degrees
                self.theta -= float(int(self.theta/TWO_PI) * TWO_PI)

                # now calculate and accumulate our position in mm
                self.x_pos_mm += mm * math.cos(self.theta)
                self.y_pos_mm += mm * math.sin(self.theta)

                if SLEEP_TIME:
                    time.sleep(SLEEP_TIME)

            self.odometry_thread_id = None

        self.odometry_thread_run = True
        self.odometry_thread_id = _thread.start_new_thread(_odometry_monitor, ())
1353414
function () {
        let _that = this[PRIVATE];
        if (_that.initialized() && _that.running()) {
            _that.gameboy.stopEmulator |= 2;
            _that.frames = 0; //Reset internal variables
        }
    }
610073
@Override
    public void run() {
	int received;

	// noinspection InfiniteLoopStatement
	while (true) {
	    // System.out.println("In PollThread loop (sleep=" + sleep +
	    // ")....");
	    try {
		if (sleep != 0) {
		    received = get_command(sleep);
		} else {
		    received = POLL_TIME_OUT;
		}

		long ctm = System.currentTimeMillis();
		now.tv_sec = (int) (ctm / 1000);
		now.tv_usec = (int) (ctm - 1000 * now.tv_sec) * 1000;
		now.tv_sec = now.tv_sec - Tango_DELTA_T;

		switch (received) {
		case POLL_COMMAND:
		    execute_cmd();
		    break;

		case POLL_TIME_OUT:
		    one_more_poll();
		    break;

		case POLL_TRIGGER:
		    one_more_trigg();
		    break;
		}

		ctm = System.currentTimeMillis();
		after.tv_sec = (int) (ctm / 1000);
		after.tv_usec = (int) (ctm - 1000 * after.tv_sec) * 1000;
		after.tv_sec = after.tv_sec - Tango_DELTA_T;

		compute_sleep_time();
	    } catch (final DevFailed e) {
		Util.out2.println("OUPS !! A thread fatal exception !!!!!!!!");
		Except.print_exception(e);
		Util.out2.println("Trying to re-enter the main loop");
	    }
	}
    }
898185
def run(self):
        
        if self.probes is None:
            self._stop = True
        while True:

            if self._stop:
                break

            self.probes_values = {
                instrument_name:
                    {probe_name: probe_instance.value for probe_name, probe_instance in probe.items()}
                for instrument_name, probe in self.probes.items()
                }

            self.updateProgress.emit(1)

            self.msleep(int(1e3*self.refresh_interval))
1235155
def wait_running(self, timeout=None):
        

        flag = self._running.wait(timeout)

        if flag is False:
            raise TimeoutExpiredError("Timeout waiting for thread to start running")
278072
def stop(self):
        '''
        
        '''
        self._stop_event.set()
        if self._func_stop_event is not None:
            self._func_stop_event.set()
        self.join(timeout=1)
        if self.isAlive():
            print('Failed to stop thread')
330132
def __start_thread(self):
        
        with self.__lock:
            if self.__nb_threads >= self._max_threads:
                # Can't create more threads
                return False

            if self._done_event.is_set():
                # We're stopped: do nothing
                return False

            # Prepare thread and start it
            name = "{0}-{1}".format(self._logger.name, self._thread_id)
            self._thread_id += 1

            thread = threading.Thread(target=self.__run, name=name)
            thread.daemon = True
            try:
                self.__nb_threads += 1
                thread.start()
                self._threads.append(thread)
                return True
            except (RuntimeError, OSError):
                self.__nb_threads -= 1
                return False
670105
def endLoop(self):
        
        if not self._inLoop:
            raise RuntimeError('run loop not started')
        self.proxy.endLoop(self._driverLoop)
        self._inLoop = False
1330368
def running(self, aProcess, aThread):
        
        if self.__state != self.ENABLED:
            self.__bad_transition(self.RUNNING)
        self.__state = self.RUNNING
827299
public synchronized void start() {
		if ((todoFlags & RECORD_CPUTIME) != 0) {
			currentStartCpuTime = getThreadCpuTime(threadId);
		} else {
			currentStartCpuTime = -1;
		}
		if ((todoFlags & RECORD_WALLTIME) != 0) {
			currentStartWallTime = System.nanoTime();
		} else {
			currentStartWallTime = -1;
		}
		isRunning = true;
	}
635771
private boolean doStart()
  {
    if (! _lifecycle.isActive()) {
      return false;
    }
    
    if (! isEnable()) {
      return false;
    }
    
    int startingCount = _startingCount.get();

    int threadCount = _threadCount.get() + startingCount;

    if (_threadMax < threadCount) {
      onThreadMax();
      
      return false;
    }
    else if (! isIdleTooLow(startingCount)) {
      return false;
    }
    
    _idleCount.incrementAndGet();

    startConnection();
      
    return true;
  }
1029229
def start_sync(self):
        
        if self._syncing:
            return

        [c.start() for c in self._controllers]
        [c.wait_to_start() for c in self._controllers]
        self._primitive_manager.start()
        self._primitive_manager._running.wait()

        self._syncing = True

        logger.info('Starting robot synchronization.')
660678
public void stopDrag() {
        mPhysicsDragger.stopDrag();

        mPhysicsContext.runOnPhysicsThread(new Runnable() {
            @Override
            public void run() {
                if (mRigidBodyDragMe != null) {
                    NativePhysics3DWorld.stopDrag(getNative());
                    mRigidBodyDragMe = null;
                }
            }
        });
    }
191275
private static synchronized void start() throws IOException {
        if (s_tracer == null) {
            final VoltTrace tracer = new VoltTrace();
            final Thread thread = new Thread(tracer);
            thread.setDaemon(true);
            thread.start();
            s_tracer = tracer;
        }
    }
60162
def endLoop(self, useDriverLoop):
        '''
        
        '''
        self._queue = []
        self._driver.stop()
        if useDriverLoop:
            self._driver.endLoop()
        else:
            self._iterator = None
        self.setBusy(True)
792882
def run(self):
        
        try:
            if self.aotask is None:
                print u"You must arm the calibration first"
                return
            # acquire data and stop task, lock must have been release by
            # previous reset
            self.daq_lock.acquire()
            self.aotask.StartTask()
            self.aitask.StartTask()

            # blocking read
            data = self.aitask.read()

            # write task should always be shorter than read
            # self.aotask.WaitUntilTaskDone(10)

            self.nacquired += 1
            
            self.aitask.stop()
            self.aotask.stop()
            
        except:
            print u'ERROR! TERMINATE!'
            self.daq_lock.release()
            self.stop()
            raise

        return data
1073367
def initialize_system_sync(self):
        

        retval = self._command_task.sync_command(['_query_systemstate'])

        self.maximum_connections = retval['max_connections']

        for conn in retval['active_connections']:
            self._connections[conn] = {'handle': conn, 'connection_id': len(self._connections)}
            self.disconnect_sync(0)

        # If the dongle was previously left in a dirty state while still scanning, it will
        # not allow new scans to be started.  So, forcibly stop any in progress scans.
        # This throws a hardware error if scanning is not in progress which should be ignored.
        try:
            self.stop_scan()
        except HardwareError:
            # If we errored our it is because we were not currently scanning, so make sure
            # we update our self.scanning flag (which would not be updated by stop_scan since
            # it raised an exception.)
            self.scanning = False

        self._command_task.sync_command(['_set_mode', 0, 0]) #Disable advertising

        self._logger.info("BLED112 adapter supports %d connections", self.maximum_connections)