diff --git a/CHANGELOG.md b/CHANGELOG.md index 73f4221..55e33aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [未发布 Unreleased] +- 给三个翻译节点的网络请求加上超时(连接 10 秒、读取 30 秒)。此前 requests 默认永不超时,对端连上却不回包会把整个工作流队列无限期堵死且无任何提示;百度翻译节点的网络异常也统一转成可读报错 +- Added timeouts to the three translator nodes (10s connect, 30s read). requests never times out by default, so a server that accepted the connection but never replied would block the whole workflow queue indefinitely with nothing reported; network failures in the Baidu node are now reported as readable errors too - 修复自定义图像保存节点把图片写到进程工作目录、并且无视 ComfyUI `--output-directory` 设置的问题;现在始终保存到 ComfyUI 的输出目录下的 `Custom_Save_Image` 子目录 - Fixed Custom Save Image writing to the process working directory and ignoring ComfyUI's `--output-directory`; it now always saves under ComfyUI's own output directory, in the `Custom_Save_Image` subfolder - 数学表达式计算节点支持三角函数、对数指数和常量(`sin`/`cos`/`tan`/`atan2`/`sqrt`/`log`/`exp`/`pi`/`e` 等),三角函数以弧度为单位,可用 `radians()` 转换 diff --git a/README.md b/README.md index 1d6ee92..aaa2cda 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ This is a custom node utility package developed for ComfyUI. Initially created f ## 最新更新 / Last Update ### [未发布 Unreleased] +- 给三个翻译节点的网络请求加上超时(连接 10 秒、读取 30 秒)。此前 requests 默认永不超时,对端连上却不回包会把整个工作流队列无限期堵死且无任何提示;百度翻译节点的网络异常也统一转成可读报错 +- Added timeouts to the three translator nodes (10s connect, 30s read). requests never times out by default, so a server that accepted the connection but never replied would block the whole workflow queue indefinitely with nothing reported; network failures in the Baidu node are now reported as readable errors too - 修复自定义图像保存节点把图片写到进程工作目录、并且无视 ComfyUI `--output-directory` 设置的问题;现在始终保存到 ComfyUI 的输出目录下的 `Custom_Save_Image` 子目录 - Fixed Custom Save Image writing to the process working directory and ignoring ComfyUI's `--output-directory`; it now always saves under ComfyUI's own output directory, in the `Custom_Save_Image` subfolder - 数学表达式计算节点支持三角函数、对数指数和常量(`sin`/`cos`/`tan`/`atan2`/`sqrt`/`log`/`exp`/`pi`/`e` 等),三角函数以弧度为单位,可用 `radians()` 转换 diff --git a/json/Baidu_Translater_config.json b/json/Baidu_Translater_config.json index 9f51630..297d857 100644 --- a/json/Baidu_Translater_config.json +++ b/json/Baidu_Translater_config.json @@ -1,4 +1,4 @@ { - "baidu_appid": "", - "baidu_appkey": "" + "baidu_appid": "English", + "baidu_appkey": "English" } \ No newline at end of file diff --git a/nodes/aio_translater.py b/nodes/aio_translater.py index 9cbb106..f7e889c 100644 --- a/nodes/aio_translater.py +++ b/nodes/aio_translater.py @@ -1,6 +1,10 @@ import json import requests +# (连接超时, 读取超时)。requests 默认永不超时,而节点是在工作流线程里同步执行的, +# 对端连上却不回包就会把整个队列永久堵死,且没有任何报错可循。 +TRANSLATE_TIMEOUT = (10, 30) + class AIOTranslater: def __init__(self): pass @@ -88,7 +92,8 @@ class AIOTranslater: 'referer': 'https://transmart.qq.com/zh-CN/index' } try: - response = requests.post(url, headers=headers, data=json.dumps(post_data)) + response = requests.post(url, headers=headers, data=json.dumps(post_data), + timeout=TRANSLATE_TIMEOUT) result = response.json() if response.status_code != 200 or 'auto_translation' not in result or not result['auto_translation']: error_msg = f"Translation failed with status code {response.status_code}: {result.get('error_msg', 'Unknown error')}" diff --git a/nodes/baidu_translater.py b/nodes/baidu_translater.py index 5a6efb5..1fc690d 100644 --- a/nodes/baidu_translater.py +++ b/nodes/baidu_translater.py @@ -1,6 +1,10 @@ import os import json import requests + +# (连接超时, 读取超时)。requests 默认永不超时,而节点是在工作流线程里同步执行的, +# 对端连上却不回包就会把整个队列永久堵死,且没有任何报错可循。 +TRANSLATE_TIMEOUT = (10, 30) import random from hashlib import md5 @@ -129,8 +133,15 @@ class BaiduTranslater: headers = {'Content-Type': 'application/x-www-form-urlencoded'} payload = {'appid': self.appid, 'q': query, 'from': from_lang, 'to': to_lang, 'salt': salt, 'sign': sign} - r = requests.post(url, data=payload, headers=headers) - result = r.json() + try: + r = requests.post(url, data=payload, headers=headers, timeout=TRANSLATE_TIMEOUT) + result = r.json() + except requests.exceptions.RequestException as e: + # 与另外两个翻译节点保持一致:网络层的失败也转成可读的 RuntimeError, + # 而不是把 requests 的异常原样抛给 ComfyUI。 + error_msg = f"Error during translation: {e}" + print(error_msg) + raise RuntimeError(error_msg) if r.status_code != 200 or 'error_code' in result: error_msg = f"Translation failed with status code {r.status_code}: {result.get('error_msg', 'Unknown error')}" print(error_msg) diff --git a/nodes/tencent_translater.py b/nodes/tencent_translater.py index 8fc0528..cb636a6 100644 --- a/nodes/tencent_translater.py +++ b/nodes/tencent_translater.py @@ -1,6 +1,10 @@ import json import requests +# (连接超时, 读取超时)。requests 默认永不超时,而节点是在工作流线程里同步执行的, +# 对端连上却不回包就会把整个队列永久堵死,且没有任何报错可循。 +TRANSLATE_TIMEOUT = (10, 30) + class TencentTranslater: def __init__(self): pass @@ -112,7 +116,8 @@ class TencentTranslater: 'referer': 'https://transmart.qq.com/zh-CN/index' } try: - response = requests.post(url, headers=headers, data=json.dumps(post_data)) + response = requests.post(url, headers=headers, data=json.dumps(post_data), + timeout=TRANSLATE_TIMEOUT) result = response.json() if response.status_code != 200 or 'auto_translation' not in result or not result['auto_translation']: error_msg = f"Translation failed with status code {response.status_code}: {result.get('error_msg', 'Unknown error')}"