From 87a1e0d7895c11d578b85a9688ec0453949d790f 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: Wed, 7 Aug 2024 17:13:50 +0800 Subject: [PATCH] GeneratorExit --- LunaTranslator/LunaTranslator/translator/baiduqianfan.py | 3 ++- LunaTranslator/LunaTranslator/translator/basetranslator.py | 3 +++ LunaTranslator/LunaTranslator/translator/claude.py | 2 ++ LunaTranslator/LunaTranslator/translator/cohere.py | 2 ++ LunaTranslator/LunaTranslator/translator/gptcommon.py | 4 +++- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/LunaTranslator/LunaTranslator/translator/baiduqianfan.py b/LunaTranslator/LunaTranslator/translator/baiduqianfan.py index 0d89c294..cf73b0c5 100644 --- a/LunaTranslator/LunaTranslator/translator/baiduqianfan.py +++ b/LunaTranslator/LunaTranslator/translator/baiduqianfan.py @@ -65,7 +65,8 @@ class TS(basetrans): msg = json_data["result"].replace("\n\n", "\n").strip() yield msg message += msg - + except GeneratorExit: + return except: print_exc() raise Exception(response_data) diff --git a/LunaTranslator/LunaTranslator/translator/basetranslator.py b/LunaTranslator/LunaTranslator/translator/basetranslator.py index 17993f67..9dcc727d 100644 --- a/LunaTranslator/LunaTranslator/translator/basetranslator.py +++ b/LunaTranslator/LunaTranslator/translator/basetranslator.py @@ -384,6 +384,9 @@ class basetrans(commonbase): __callback(res, 0) if all([_ is not None for _ in collectiterres]): self.cachesetatend(contentsolved, "".join(collectiterres)) + + except GeneratorExit: + pass except Exception as e: if self.using and globalconfig["showtranexception"]: if isinstance(e, ArgsEmptyExc): diff --git a/LunaTranslator/LunaTranslator/translator/claude.py b/LunaTranslator/LunaTranslator/translator/claude.py index 14edb94a..fe0f6404 100644 --- a/LunaTranslator/LunaTranslator/translator/claude.py +++ b/LunaTranslator/LunaTranslator/translator/claude.py @@ -118,6 +118,8 @@ class TS(basetrans): msg = json_data["content_block"]["text"] yield msg message += msg + except GeneratorExit: + return except: print_exc() raise Exception(response_data) diff --git a/LunaTranslator/LunaTranslator/translator/cohere.py b/LunaTranslator/LunaTranslator/translator/cohere.py index ed786f5c..54d9c099 100644 --- a/LunaTranslator/LunaTranslator/translator/cohere.py +++ b/LunaTranslator/LunaTranslator/translator/cohere.py @@ -155,6 +155,8 @@ class TS(basetrans): elif t == "stream-end": break + except GeneratorExit: + return except: print_exc() raise Exception(response_data) diff --git a/LunaTranslator/LunaTranslator/translator/gptcommon.py b/LunaTranslator/LunaTranslator/translator/gptcommon.py index 6c7f3d3b..bb54aa42 100644 --- a/LunaTranslator/LunaTranslator/translator/gptcommon.py +++ b/LunaTranslator/LunaTranslator/translator/gptcommon.py @@ -96,7 +96,9 @@ class gptcommon(basetrans): continue yield msg message += msg - + + except GeneratorExit: + return except: print_exc() raise Exception(response_data)