def _get_thread_id(self):
     if hasattr(self, "_thread_id"):
         return self._thread_id
     for tid, tobj in _active.items():
         if tobj is self:
             self._thread_id = tid
             return tid
 def _get_thread_id(self):
     if hasattr(self, "_thread_id"):
         return self._thread_id
     for tid, tobj in _active.items():
         if tobj is self:
             self._thread_id = tid
             return tid
示例#3
0
    def stop(self):
        """
		Stop the thread (change internal variable)

		Returns:
			SimpleThread: self
		"""
        if not self._running: return
        self.__del__()
        try:
            self._internalThread
            self._running
        except:
            return self
        if self._internalThread is not None:
            # Credit to liuw (https://gist.github.com/liuw/2407154)
            for thread_id, thread_object in _active.items():
                if self._internalThread is thread_object:
                    response = ctypes.pythonapi.PyThreadState_SetAsyncExc(
                        thread_id, ctypes.py_object(SimpleClose))
                    if response > 1:
                        ctypes.pythonapi.PyThreadState_SetAsyncExc(
                            thread_id, 0)
                        raise SystemError("PyThreadState_SetAsyncExc failed")
        self._running = False  # Set that thread isn't running
        return self  # Return self
示例#4
0
    def stop(self, force=False):
        self._stop.set()

        if force:
            for tid, tobj in _active.items():
                if tobj is self:
                    _async_raise(tid, ThreadExit)
                    return
示例#5
0
    def stop(self, force=False):
        self._stop.set()

        if force:
            for tid, tobj in _active.items():
                if tobj is self:
                    _async_raise(tid, ThreadExit)
                    return
示例#6
0
    def _get_my_tid(self):
        if not self.is_alive():
            raise ThreadError("the thread is not active")

        if hasattr(self, "_thread_id"):
            return self._thread_id

        for tid, tobj in _active.items():
            if tobj is self:
                self._thread_id = tid
                return tid

        raise AssertionError("could not determine the thread's id")
def exit_cleanup(sig, tmp):
    counter.led.off()
    signal.signal(signal.SIGINT, old_signal_handler)
    thrds = active_threads.items()
    for id, thrd in thrds:
        if thrd in [counter, cheer]:
            r = ctypes.pythonapi.PyThreadState_SetAsyncExc(
                id, ctypes.py_object(SystemExit))
            if r > 1:
                print('Failed to stop sensor')
                sys.exit(1)
            else:
                thrd.join()
    sys.exit(0)
 def not_in_use(self):
     if not self.sensor:
         return
     if hasattr(self.sensor, '_thread_id'):
        id = self.sensor._thread_id
     else:
        for id, thrd in active_threads.items():
            if thrd == self.sensor:
                break
     r = ctypes.pythonapi.PyThreadState_SetAsyncExc(id,ctypes.py_object(SystemExit))
     if r > 1:
         print('Failed to stop sensor')
         sys.exit(1)
     else:
         self.sensor.join()
         self.sensor = None
示例#9
0
def exit_cleanup(sig, tmp):
    print("exiting ... cleanning up ...")
    signal.signal(signal.SIGINT, old_signal_handler)
    thrds = active_threads.items()
    for id, thrd in thrds:
        if thrd in my_threads:
            try:
                r = ctypes.pythonapi.PyThreadState_SetAsyncExc(id,ctypes.py_object(SystemExit))
                if r > 1:
                    print('Failed to stop sensor')
                    sys.exit(1)
                else:
                    thrd.join()
            except:
                continue
    sys.exit(0)
示例#10
0
 def raise_exc(self, excobj):
     if self.isAlive():
         for tid, tobj in _active.items():
             if tobj is self:
                 self.__async_raise__(tid, excobj)
                 return