Your Name commited on
Commit
d0e3ca7
1 Parent(s): 61b4ea6

更好的多线程交互性

Browse files
crazy_functions/{全项目切换英文.py → 代码重写为全英文_多线程.py} RENAMED
@@ -37,10 +37,24 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
37
  for h in handles:
38
  h.daemon = True
39
  h.start()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- # 等待各个线程逐一完成
42
  for index, h in enumerate(handles):
43
- h.join()
44
  fp = file_manifest[index]
45
  gpt_say = mutable_return[index]
46
  i_say_show_user = i_say_show_user_buffer[index]
@@ -51,9 +65,9 @@ def 全项目切换英文(txt, top_p, temperature, chatbot, history, sys_prompt,
51
  chatbot.append((i_say_show_user, f'[Local Message] 已完成{os.path.abspath(fp)}的转化,\n\n存入{os.path.abspath(where_to_relocate)}'))
52
  history.append(i_say_show_user); history.append(gpt_say)
53
  yield chatbot, history, '正常'
54
- time.sleep(2)
55
 
56
- # 结束
57
  res = write_results_to_file(history)
58
- chatbot.append(("完成了吗?", res))
59
  yield chatbot, history, '正常'
 
37
  for h in handles:
38
  h.daemon = True
39
  h.start()
40
+ chatbot.append(('开始了吗?', f'多线程操作已经开始'))
41
+ yield chatbot, history, '正常'
42
+
43
+ # 循环轮询各个线程是否执行完毕
44
+ cnt = 0
45
+ while True:
46
+ time.sleep(1)
47
+ th_alive = [h.is_alive() for h in handles]
48
+ if not any(th_alive): break
49
+ stat = ['执行中' if alive else '已完成' for alive in th_alive]
50
+ stat_str = '|'.join(stat)
51
+ cnt += 1
52
+ chatbot[-1] = (chatbot[-1][0], f'多线程操作已经开始,完成情况: {stat_str}' + ''.join(['.']*(cnt%4)))
53
+ yield chatbot, history, '正常'
54
 
55
+ # 把结果写入文件
56
  for index, h in enumerate(handles):
57
+ h.join() # 这里其实不需要join了,肯定已经都结束了
58
  fp = file_manifest[index]
59
  gpt_say = mutable_return[index]
60
  i_say_show_user = i_say_show_user_buffer[index]
 
65
  chatbot.append((i_say_show_user, f'[Local Message] 已完成{os.path.abspath(fp)}的转化,\n\n存入{os.path.abspath(where_to_relocate)}'))
66
  history.append(i_say_show_user); history.append(gpt_say)
67
  yield chatbot, history, '正常'
68
+ time.sleep(1)
69
 
70
+ # 备份一个文件
71
  res = write_results_to_file(history)
72
+ chatbot.append(("给爷一份任务执行报告", res))
73
  yield chatbot, history, '正常'
functional_crazy.py CHANGED
@@ -7,13 +7,13 @@ def get_crazy_functionals():
7
  from crazy_functions.解析项目源代码 import 解析一个C项目的头文件
8
  from crazy_functions.解析项目源代码 import 解析一个C项目
9
  from crazy_functions.高级功能函数模板 import 高阶功能模板函数
10
- from crazy_functions.全项目切换英文 import 全项目切换英文
11
 
12
  return {
13
  "[实验] 请解析并解构此项目本身": {
14
  "Function": 解析项目本身
15
  },
16
- "[实验] 把此项目代码切换成全英文": {
17
  "Color": "stop", # 按钮颜色
18
  "Function": 全项目切换英文
19
  },
 
7
  from crazy_functions.解析项目源代码 import 解析一个C项目的头文件
8
  from crazy_functions.解析项目源代码 import 解析一个C项目
9
  from crazy_functions.高级功能函数模板 import 高阶功能模板函数
10
+ from crazy_functions.代码重写为全英文_多线程 import 全项目切换英文
11
 
12
  return {
13
  "[实验] 请解析并解构此项目本身": {
14
  "Function": 解析项目本身
15
  },
16
+ "[实验] 把本项目代码切换成全英文": {
17
  "Color": "stop", # 按钮颜色
18
  "Function": 全项目切换英文
19
  },