From 07071ed64e49014d6ebc41d7b17ccb5801774108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sun, 3 Mar 2024 02:08:05 +0800 Subject: [PATCH] stream interrupt --- LunaTranslator/LunaTranslator/gui/translatorUI.py | 2 -- .../LunaTranslator/translator/basetranslator.py | 14 ++++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index dcc6fc51..2a0a5698 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -74,9 +74,7 @@ class QUnFrameWindow(resizableframeless): try: if len(iter_res_info): starting,klass=iter_res_info - print(starting,klass,res) if not starting: - print(self.saveiterclasspointer[klass]) self.translate_text.insertatpointer(self.saveiterclasspointer[klass],res) self.saveiterclasspointer[klass]=self.translate_text.getcurrpointer() return diff --git a/LunaTranslator/LunaTranslator/translator/basetranslator.py b/LunaTranslator/LunaTranslator/translator/basetranslator.py index fc5f0637..abc236fa 100644 --- a/LunaTranslator/LunaTranslator/translator/basetranslator.py +++ b/LunaTranslator/LunaTranslator/translator/basetranslator.py @@ -79,6 +79,7 @@ class basetrans(commonbase): self._safe_private_init() self.lastrequesttime=0 + self.requestid=0 self._cache={} self.newline=None @@ -248,9 +249,9 @@ class basetrans(commonbase): if is_auto_run and self.onlymanual: continue - + self.requestid+=1 try: - checktutukufunction=lambda:( (embedcallback is not None) or self.queue.empty()) and self.using + checktutukufunction=lambda:( (embedcallback is not None) or self.queue.empty()) and self.using if checktutukufunction(): def reinitandtrans(): if self.needreinit: @@ -266,8 +267,13 @@ class basetrans(commonbase): callback(_,embedcallback,is_iter_res) collectiterres.append(_) if isinstance(res,types.GeneratorType): - for _res in res: - __callback(_res,True) + def _iterget(): + rid=self.requestid + for _res in res: + if self.requestid!=rid:break + __callback(_res,True) + timeoutfunction(_iterget,checktutukufunction=checktutukufunction ) + else: __callback(res,False) self.cachesetatend(contentsolved,''.join(collectiterres))