3v324v23 commited on
Commit
5948dca
1 Parent(s): 3041858

加线程锁

Browse files
Files changed (1) hide show
  1. request_llm/bridge_newbing.py +5 -1
request_llm/bridge_newbing.py CHANGED
@@ -415,6 +415,7 @@ load_message = "等待NewBing响应。"
415
  """
416
  import time
417
  import importlib
 
418
  from toolbox import update_ui, get_conf, trimmed_format_exc
419
  from multiprocessing import Process, Pipe
420
 
@@ -428,6 +429,7 @@ class GetNewBingHandle(Process):
428
  self.local_history = []
429
  self.check_dependency()
430
  self.start()
 
431
 
432
  def check_dependency(self):
433
  try:
@@ -543,6 +545,7 @@ class GetNewBingHandle(Process):
543
  """
544
  这个函数运行在主进程
545
  """
 
546
  self.parent.send(kwargs) # 发送请求到子进程
547
  while True:
548
  res = self.parent.recv() # 等待newbing回复的片段
@@ -553,7 +556,7 @@ class GetNewBingHandle(Process):
553
  break
554
  else:
555
  yield res # newbing回复的片段
556
- return
557
 
558
 
559
  def preprocess_newbing_out(s):
@@ -599,6 +602,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
599
 
600
  watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可
601
  response = ""
 
602
  for response in newbing_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=sys_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
603
  observe_window[0] = preprocess_newbing_out_simple(response)
604
  if len(observe_window) >= 2:
 
415
  """
416
  import time
417
  import importlib
418
+ import threading
419
  from toolbox import update_ui, get_conf, trimmed_format_exc
420
  from multiprocessing import Process, Pipe
421
 
 
429
  self.local_history = []
430
  self.check_dependency()
431
  self.start()
432
+ self.threadLock = threading.Lock()
433
 
434
  def check_dependency(self):
435
  try:
 
545
  """
546
  这个函数运行在主进程
547
  """
548
+ self.threadLock.acquire()
549
  self.parent.send(kwargs) # 发送请求到子进程
550
  while True:
551
  res = self.parent.recv() # 等待newbing回复的片段
 
556
  break
557
  else:
558
  yield res # newbing回复的片段
559
+ self.threadLock.release()
560
 
561
 
562
  def preprocess_newbing_out(s):
 
602
 
603
  watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可
604
  response = ""
605
+ observe_window[0] = "[Local Message]: 等待NewBing响应中 ..."
606
  for response in newbing_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=sys_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
607
  observe_window[0] = preprocess_newbing_out_simple(response)
608
  if len(observe_window) >= 2: