流式输出中断问题
lwinhong opened this issue · comments
#流式输出事件生成器
async def chat_stream_event_generator(request: Request, chatStream):
for chunck in chatStream:
try:
if await request.is_disconnected():
print("连接已中断")
break
start_time = time.time()
print(f"{start_time}->{chunck[0]}")
yield chunck[0]
print(f"{start_time}->写入完成")
except (BrokenPipeError, ConnectionResetError) as e:
print(f"客户端已断开: {e}")
break
except Exception as e:
print(f"发送数据引发了一个一次: {e}")
break
print("流式输出事件生成器结束")
关于流式输入中断问题
1.前端请求已经Abort断开。if await request.is_disconnected(): 判断无效
2.断开之后,这个循环卡在 yield chunck[0]
这位大神有什么解决方案吗