diff --git a/app.py b/app.py index 221a83e..072fc7c 100644 --- a/app.py +++ b/app.py @@ -8,8 +8,9 @@ from multiprocessing import Pool # 启动通道 def start_process(channel_type): + # 若为多进程启动,子进程无法直接访问主进程的内存空间,重新创建config类 + config.load_config() model_type = config.conf().get("model").get("type") - # load config log.info("[INIT] Start up: {} on {}", model_type, channel_type) # create channel @@ -18,7 +19,6 @@ def start_process(channel_type): # startup channel channel.startup() - if __name__ == '__main__': try: # load config diff --git a/channel/http/http_channel.py b/channel/http/http_channel.py index 3dc726f..2464f61 100644 --- a/channel/http/http_channel.py +++ b/channel/http/http_channel.py @@ -73,6 +73,8 @@ class HttpChannel(Channel): context['from_user_id'] = str(id) reply = super().build_reply_content(data["msg"], context) if img_match_prefix: + if not isinstance(reply, list): + return reply images = "" for url in reply: images += f"[!['IMAGE_CREATE']({url})]({url})\n" diff --git a/channel/telegram/telegram_channel.py b/channel/telegram/telegram_channel.py index 4bcd92e..0e588f0 100644 --- a/channel/telegram/telegram_channel.py +++ b/channel/telegram/telegram_channel.py @@ -52,6 +52,8 @@ class TelegramChannel(Channel): img_urls = super().build_reply_content(msg.text, context) if not img_urls: return + if not isinstance(img_urls, list): + return img_urls for url in img_urls: # 图片下载 pic_res = requests.get(url, stream=True) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index bac92b7..60b9086 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -171,7 +171,8 @@ class WechatChannel(Channel): img_urls = super().build_reply_content(query, context) if not img_urls: return - + if not isinstance(img_urls, list): + return img_urls for url in img_urls: # 图片下载 pic_res = requests.get(url, stream=True) diff --git a/model/bing/new_bing_model.py b/model/bing/new_bing_model.py index b22244b..c062158 100644 --- a/model/bing/new_bing_model.py +++ b/model/bing/new_bing_model.py @@ -97,7 +97,7 @@ class BingModel(Model): image_generator = ImageGen(cookie_value) img_list = image_generator.get_images(query) log.info("[NewBing] image_list={}".format(img_list)) - return img_list[0] + return img_list except Exception as e: log.exception(e) return None