import threading class NotmuchThread(threading.Thread): def __init__(self): super(NotmuchThread, self).__init__() self.job_waiting = threading.Condition() self.job_queue = [] def run(self): from notmuch.database import Database self.db = Database() job = None print "Aquiring lock" with self.job_waiting: if len(self.job_queue) < 1: print "Job queue empty so waiting" while True: ready = self.job_waiting.wait(1) if ready: break if len(self.job_queue) > 0: break print "Got job, releasing lock" self.search_threads("tag:inbox") def search_threads(self, query_string): query = self.db.create_query(query_string) print("%X" % query._query) threads = query.search_threads() return threads test_thread = NotmuchThread() test_thread.start() with test_thread.job_waiting: test_thread.job_queue.append() test_thread.job_waiting.notify() import time; time.sleep(1) test_thread.join()