From 976f9731921853d3098729e4ba8ef6b2d377e9e7 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 29 十月 2024 22:40:38 +0800
Subject: [PATCH] 代码优化

---
 app/api/report.py |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/app/api/report.py b/app/api/report.py
index 254695d..22c9bf6 100644
--- a/app/api/report.py
+++ b/app/api/report.py
@@ -83,6 +83,15 @@
                 asyncio.create_task(forward_to_service()),
                 asyncio.create_task(forward_to_client())
             ]
+            done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
+
+            # 鍙栨秷鏈畬鎴愮殑浠诲姟
+            for task in pending:
+                task.cancel()
+                try:
+                    await task
+                except asyncio.CancelledError:
+                    pass
 
         except WebSocketDisconnect as e:
             print(f"WebSocket connection closed with code {e.code}: {e.reason}")
@@ -91,7 +100,7 @@
         except Exception as e:
             print(f"Exception occurred: {e}")
         finally:
-            print("Cleaning up resources")
+            print("Cleaning up resources of bisheng report")
             # 鍙栨秷鎵�鏈変换鍔�
             for task in tasks:
                 if not task.done():

--
Gitblit v1.8.0