class BackgroundDownloader(Thread): """It seems, such implementation does not cause slight lags in qt (as opposed to QThread one)""" def __init__(self, pause): Thread.__init__(self) self.mayUpdate = False self.hasItemsToUpdate = True self.waitFor = (pause * 60) / 2 self.dbUpdater = DBBackgroundUpdater() self.event = Event() def run(self): print "Imma in yȯr background, updating yȯrz db" while not self.event.is_set(): if self.mayUpdate and self.hasItemsToUpdate: item = self.dbUpdater.getSomeItem() if item is None: self.hasItemsToUpdate = False print "No more items to update" else: self.dbUpdater.addExamples(item, JishoClient.getExamples(item.character)) # print 'Added examples for ' + item.character print "Attempted to add examples for " + item.character self.event.wait(self.waitFor) def stop(self): self.event.set()
def __init__(self, pause): Thread.__init__(self) self.mayUpdate = False self.hasItemsToUpdate = True self.waitFor = (pause * 60) / 2 self.dbUpdater = DBBackgroundUpdater() self.event = Event()