def run(self): currentThread = QThread.currentThread() def __download(fileName, url): try: if currentThread.isInterruptionRequested(): return r = self.session.get(url, stream=True) if not path.exists(fileName) or path.getsize(fileName) != int(r.headers['Content-Length']): with open(fileName, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: f.write(chunk) self.logger.info(f'{fileName} 下载完成') else: self.logger.info(f'{fileName} 跳过下载') except Exception as e: self.logger.warning(f'下载{fileName}:{url}异常: {e}') finally: self.tick.emit() with ThreadPool(max_workers=3) as executor: for fileName, url in self.audios: executor.submit(__download, fileName, url) self.done.emit()
def run(self): currentThread = QThread.currentThread() for row in self.api.getSentencesWithoutTranslate(): if currentThread.isInterruptionRequested(): return self.api.insertSentenceTranslates(row) self.tick.emit() self.done.emit()
def run(self): currentThread = QThread.currentThread() for row in self.api.getWordsWithoutExample(): if currentThread.isInterruptionRequested(): return self.api.insertWordExamples(row['id']) self.tick.emit() self.done.emit()
def run(self): currentThread = QThread.currentThread() for word in self.api.getAllWords(): if currentThread.isInterruptionRequested(): return self.api.insertWord(word) self.tick.emit() self.done.emit()
def inMainThread(self): return self._mainThread == QThread.currentThread()
def setupThreads(self): self._mainThread = QThread.currentThread()