def __init__(self, event_queue, search_queue, results_queue, path_filter, file_count=None): if file_count is None: # it's not that important... class ObjectWithValue(object): def __init__(self, val): self.value = val file_count = ObjectWithValue(0) self._file_count = file_count self.event_queue = event_queue self.search_queue = search_queue self.path_filter = path_filter self.results_queue = results_queue self.dblock = threading.Lock() self.dbqueue = queue.Queue(maxsize=1) search_thread = threading.Thread(target=log_exceptions(self.poll_search), name="[db] find handler") search_thread.daemon = True search_thread.start() file_thread = threading.Thread(target=log_exceptions(self.poll_events), name="[db] file event handler") file_thread.daemon = True file_thread.start() db_thread = threading.Thread(target=log_exceptions(self.poll_db), name="[db] query runner") db_thread.daemon = True db_thread.start()
def run(self): rootLogger = logging.getLogger() rootLogger.addHandler(QueueHandler(self.status_queue, level=logging.INFO)) logging.info("scanning ...") def _doit(): try: self.finder = FileFinder(self.opt.base_path, path_filter=self.opt.path_filter, quit_indicator=QUITTING_TIME) self.finder.populate() curses.wrapper(self._run) finally: QUITTING_TIME.set() work_thread = threading.Thread(target=log_exceptions(_doit), name="[curses] master") work_thread.start() # the main thread is just going to wait till someone tells it to quit try: QUITTING_TIME.wait() except KeyboardInterrupt: # somehow the main thread fails to exit when it is the one # to receive KeyboardInterrupt ! QUITTING_TIME.set()