'Main loop for Threading.
This function is the main loop of the thread.
Returns
bool
True when the thread exits nicely.'

def run(self):

    logSys.info('Observer    start...')
    self.add_named_timer('DB_PURGE', self.__db_purge_interval, 'db_purge')
    __meth = {'call': self.call_lambda, 'db_set': self.db_set, 'db_purge': self.db_purge, 'is_alive': self.isAlive, 'is_active': self.isActive, 'start': self.start, 'stop': self.stop, 'nop': (lambda : ()), 'shutdown': (lambda : ())}
    try:
        self.add('is_alive')
        while self.active:
            self.idle = False
            while (not self._paused):
                try:
                    ev = None
                    with self._queue_lock:
                        if len(self._queue):
                            ev = self._queue.pop(0)
                    if (ev is None):
                        break
                    meth = ev[0]
                    if (not callable(ev[0])):
                        meth = (__meth.get(meth) or getattr(self, meth))
                    meth(*ev[1:])
                except Exception as e:
                    logSys.error('%s', e, exc_info=True)
            n = self._notify
            if n:
                self.idle = True
                n.wait(self.sleeptime)
                n.clear()
                if self._paused:
                    continue
            else:
                time.sleep(ObserverThread.DEFAULT_SLEEP_INTERVAL)
                if (not self.is_full):
                    break
        logSys.info('Observer    stopped,    %s    events    remaining.', len(self._queue))
    except Exception as e:
        logSys.error('Observer    stopped    after    error:    %s', e, exc_info=True)
    with self._queue_lock:
        self._queue = []
    self.idle = True
    return True
