mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-22 23:11:05 +08:00
loader.py: 模型重载 定义 generatorAnswer 增加 AnswerResultStream 定义generate_with_callback收集器,在每次响应时将队列数据同步到AnswerResult requirements.txt 变更项目依赖
31 lines
975 B
Python
31 lines
975 B
Python
# Python program raising
|
|
# exceptions in a python
|
|
# thread
|
|
|
|
import threading
|
|
import ctypes
|
|
import time
|
|
|
|
|
|
class ThreadWithException(threading.Thread):
|
|
|
|
def get_id(self):
|
|
return self.ident
|
|
|
|
def raise_exception(self):
|
|
"""raises the exception, performs cleanup if needed"""
|
|
try:
|
|
thread_id = self.get_id()
|
|
tid = ctypes.c_long(thread_id)
|
|
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(SystemExit))
|
|
if res == 0:
|
|
# pass
|
|
raise ValueError("invalid thread id")
|
|
elif res != 1:
|
|
# """if it returns a number greater than one, you're in trouble,
|
|
# and you should call it again with exc=NULL to revert the effect"""
|
|
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
|
|
raise SystemError("PyThreadState_SetAsyncExc failed")
|
|
except Exception as err:
|
|
print(err)
|