From f2359e0442d2aad749df2bb613f8bd5f3ea99309 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Mar 2023 01:32:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E5=A5=BD=E7=9A=84=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=BA=A4=E4=BA=92=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...目切换英文.py => 代码重写为全英文_多线程.py} | 24 +++++++++++++++---- functional_crazy.py | 4 ++-- 2 files changed, 21 insertions(+), 7 deletions(-) rename crazy_functions/{全项目切换英文.py => 代码重写为全英文_多线程.py} (77%) diff --git a/crazy_functions/全项目切换英文.py b/crazy_functions/代码重写为全英文_多线程.py similarity index 77% rename from crazy_functions/全项目切换英文.py rename to crazy_functions/代码重写为全英文_多线程.py index 8015f55..13500cf 100644 --- a/crazy_functions/全项目切换英文.py +++ b/crazy_functions/代码重写为全英文_多线程.py @@ -37,10 +37,24 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt, for h in handles: h.daemon = True h.start() + chatbot.append(('开始了吗?', f'多线程操作已经开始')) + yield chatbot, history, '正常' - # 等待各个线程逐一完成 + # 循环轮询各个线程是否执行完毕 + cnt = 0 + while True: + time.sleep(1) + th_alive = [h.is_alive() for h in handles] + if not any(th_alive): break + stat = ['执行中' if alive else '已完成' for alive in th_alive] + stat_str = '|'.join(stat) + cnt += 1 + chatbot[-1] = (chatbot[-1][0], f'多线程操作已经开始,完成情况: {stat_str}' + ''.join(['.']*(cnt%4))) + yield chatbot, history, '正常' + + # 把结果写入文件 for index, h in enumerate(handles): - h.join() + h.join() # 这里其实不需要join了,肯定已经都结束了 fp = file_manifest[index] gpt_say = mutable_return[index] i_say_show_user = i_say_show_user_buffer[index] @@ -51,9 +65,9 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt, chatbot.append((i_say_show_user, f'[Local Message] 已完成{os.path.abspath(fp)}的转化,\n\n存入{os.path.abspath(where_to_relocate)}')) history.append(i_say_show_user); history.append(gpt_say) yield chatbot, history, '正常' - time.sleep(2) + time.sleep(1) - # 结束 + # 备份一个文件 res = write_results_to_file(history) - chatbot.append(("完成了吗?", res)) + chatbot.append(("给爷一份任务执行报告", res)) yield chatbot, history, '正常' diff --git a/functional_crazy.py b/functional_crazy.py index 0c3480d..a319449 100644 --- a/functional_crazy.py +++ b/functional_crazy.py @@ -7,13 +7,13 @@ def get_crazy_functionals(): from crazy_functions.解析项目源代码 import 解析一个C项目的头文件 from crazy_functions.解析项目源代码 import 解析一个C项目 from crazy_functions.高级功能函数模板 import 高阶功能模板函数 - from crazy_functions.全项目切换英文 import 全项目切换英文 + from crazy_functions.代码重写为全英文_多线程 import 全项目切换英文 return { "[实验] 请解析并解构此项目本身": { "Function": 解析项目本身 }, - "[实验] 把此项目代码切换成全英文": { + "[实验] 把本项目代码切换成全英文": { "Color": "stop", # 按钮颜色 "Function": 全项目切换英文 },