main
HuangHai 4 months ago
parent 4ce91f1f5b
commit 8c804a2e8f

@ -1,3 +1,4 @@
import asyncio
import json
import uuid
from datetime import date, datetime
@ -187,7 +188,9 @@ async def get_docx_stream(
# 记录到数据库
await db.execute("UPDATE t_bi_question SET docx_file_name = $1 WHERE id = $2", filename, question_id)
except asyncio.CancelledError:
# 客户端提前断开连接,无需处理
print("客户端断开连接")
except Exception as e:
# 如果发生异常,返回错误信息
error_response = json.dumps({
@ -200,7 +203,7 @@ async def get_docx_stream(
finally:
# 确保资源释放
if "response" in locals():
await response.aclose()
await response.close()
# 使用 StreamingResponse 返回流式结果
return StreamingResponse(

Loading…
Cancel
Save