rambo 3 mēneši atpakaļ
vecāks
revīzija
a776dd5c75

+ 9 - 11
python/api.py

@@ -257,7 +257,7 @@ async def fromExcelHandler(params: HandlerDetail):
     try:
         if cutout_res:
             return_data_check_before_detail = run_main.check_before_detail(config_data)
-            check_for_detail_first_res = await run_main.check_for_detail_first_call_back(
+            check_for_detail_first_res = run_main.check_for_detail_first_call_back(
                 return_data_check_before_detail
             )
         if isinstance(check_for_detail_first_res, partial):
@@ -328,7 +328,7 @@ async def fromExcelHandler(params: HandlerDetail):
         status="处理结束",
         msg_type="detail_result_progress",
     )
-    return
+    return True
 
 
 def group_by_style_number(data):
@@ -494,7 +494,7 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
             status="处理结束",
             msg_type="detail_result_progress",
         )
-        return
+        return True
     if is_product_scene == 1:
         if product_scene_prompt == "" or product_scene_prompt == None:
             raise UnicornException("请填写场景描述")
@@ -531,11 +531,9 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
                     goods_art_dict_info["场景图"] = save_image_path
                     new_goods_dict[goods_art_no] = goods_art_dict_info
                     continue
-                print("处理场景图2", goods_art_no)
                 aigc_clazz.center_paste_image(ceshi_image_path, save_image_path)
-                print("处理场景图3", goods_art_no)
                 try:
-                    image_path = await aigc_clazz.generateProductScene(
+                    image_path = aigc_clazz.generateProductScene(
                         save_image_path, product_scene_prompt, save_image_path
                     )
                     goods_art_dict_info["场景图"] = image_path
@@ -594,7 +592,7 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
                     continue
                 shutil.copy(ceshi_image_path, save_image_path)
                 try:
-                    image_path = await aigc_clazz.generateUpperShoes(
+                    image_path = aigc_clazz.generateUpperShoes(
                         save_image_path, model_id, save_image_path
                     )
                     goods_art_dict_info["模特图"] = image_path
@@ -646,8 +644,8 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
                 status="处理结束",
                 msg_type="detail_result_progress",
             )
-            return
-        check_for_detail_first_res = await run_main.check_for_detail_first_call_back(
+            return True
+        check_for_detail_first_res =  run_main.check_for_detail_first_call_back(
             return_data_check_before_detail
         )
         if isinstance(check_for_detail_first_res, partial):
@@ -709,7 +707,7 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
                             msg_type="upload_goods_progress",
                         )
                         try:
-                            await onlineData.uploadGoods2ThirdParty(
+                            onlineData.uploadGoods2ThirdParty(
                                 result_goods_no_dict, online_stores=online_stores
                             )
                         except Exception as e:
@@ -744,7 +742,7 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
         status="处理结束",
         msg_type="detail_result_progress",
     )
-    return
+    return True
 
 
 @app.get("/get_device_tabs", description="获取可执行程序命令列表")

+ 1 - 1
python/config.ini

@@ -12,7 +12,7 @@ port=7074
 debug=false
 env=dev
 # 线程数
-works=5
+works=1
 project=惠利玛
 is_upload=true
 [log]

+ 5 - 2
python/index.py

@@ -10,6 +10,7 @@ import uvicorn.protocols.websockets.auto
 import uvicorn.lifespan.on
 from multiprocessing import Process, freeze_support
 from service.init_load_source import init_load_source
+import socket
 
 def handle_shutdown(signum, frame):
     """关闭系统应用服务"""
@@ -30,10 +31,12 @@ async def run_server():
         APP_RUN,
         host=APP_HOST,
         port=int(PORT),
-        reload=isDebug,
         workers=int(APP_WORKS),
-        loop="auto",
+        loop="asyncio",
+        ws_ping_interval=20,  # 每 20 秒发一次 WebSocket Ping 帧
+        ws_ping_timeout=10,  # 等待 Pong 最多 10 秒
     )
+    # 创建自定义 socket
     server = uvicorn.Server(config)
     try:
         await server.serve()

+ 5 - 8
python/service/online_request/module_online_data.py

@@ -113,8 +113,7 @@ class AIGCDataRequest(object):
 
         return background
 
-    async def generateProductScene(self, local_path, prompt, save_path):
-        await asyncio.sleep(0.1)
+    def generateProductScene(self, local_path, prompt, save_path):
         imageUrl = self.uploadImage(local_path)
         print("imageUrl", imageUrl)
         data = {
@@ -139,8 +138,7 @@ class AIGCDataRequest(object):
         save_image_path = download_image_with_pil(image_url, save_path)
         return save_image_path
 
-    async def searchProgress(self, id):
-        await asyncio.sleep(0.1)
+    def searchProgress(self, id):
         """查询进度"""
         url = settings.DOMAIN + "/api/ai_image/main/search_bacth_progress"
         data = {"site": 1, "generate_ids": [id], "type": "aigc_pro"}
@@ -162,7 +160,7 @@ class AIGCDataRequest(object):
         result_image = result_image_urls[0] if len(result_image_urls) > 0 else None
         return status, result_image
 
-    async def generateUpperShoes(self, local_path, model_id, save_path):
+    def generateUpperShoes(self, local_path, model_id, save_path):
         """生成上脚图"""
         print("生成上脚图", local_path, model_id, save_path)
         imageUrl = self.uploadImage(local_path)
@@ -192,7 +190,7 @@ class AIGCDataRequest(object):
         print("generate_id", generate_id)
         while search_times > 0:
             print(f"查询第{search_times}次")
-            status, result_image = await self.searchProgress(generate_id)
+            status, result_image = self.searchProgress(generate_id)
             if status in [-1, 2]:
                 break
             time.sleep(1)
@@ -531,8 +529,7 @@ class OnlineDataRequest(object):
         loop = asyncio.get_event_loop()
         loop.create_task(message_queue.put(data))
 
-    async def uploadGoods2ThirdParty(self, goods_no_dict=None, online_stores=[]):
-        await asyncio.sleep(0.1)
+    def uploadGoods2ThirdParty(self, goods_no_dict=None, online_stores=[]):
         params = []
         message_type = "upload_goods_progress"
         if goods_no_dict == None:

+ 18 - 17
python/service/run_main.py

@@ -355,7 +355,7 @@ class RunMain:
             loop = asyncio.get_event_loop()
         except:
             loop = asyncio.new_event_loop()
-        executor = ThreadPoolExecutor(max_workers=4)
+        executor = ThreadPoolExecutor(max_workers=10)
         goods_arts = [
             goods_art_no_folder_data["folder_name"]
             for goods_art_no_folder_data in all_goods_art_no_folder_data
@@ -796,7 +796,7 @@ class RunMain:
             check_path(target_folder)
             move_folders(path_list=[one_path], target_folder=target_folder)
 
-    async def check_for_detail_first_call_back(self, data):
+    def check_for_detail_first_call_back(self, data):
         # 首次数据校验的信息返回
         # self.show_message(text="22222222222222222222222")
         # QMessageBox.critical(self, "警告", "1111111", QMessageBox.Ok)
@@ -881,7 +881,7 @@ class RunMain:
                 ],  # 每个款号需要生成的模板数据
             }
             # todo work
-            new_func = await self.detail_run_by_thread(
+            new_func = self.detail_run_by_thread(
                 config_data=kwargs["config_data"],
                 _goods_no_dict=kwargs["_goods_no_dict"],
                 temp_name=kwargs["temp_name"],
@@ -899,7 +899,7 @@ class RunMain:
             # self.run_end_sign.emit(config_data)
             return config_data
 
-    async def detail_run_by_thread(
+    def detail_run_by_thread(
         self,
         config_data,
         _goods_no_dict,
@@ -960,22 +960,24 @@ class RunMain:
                         item.get("货号", "")
                         for item in temp_info_data.get("货号资料", [])
                     ]
-                    await sendSocketMessage(
-                        code=0,
-                        msg="开始处理详情",
-                        data={
-                            "goods_no": goods_no,
-                            "temp_name": _temp_name,
-                            "status": "进行中",
-                            "goods_art_nos": goods_art_nos,
-                        },
-                        msg_type="detail_progress",
+                    asyncio.get_event_loop().create_task(
+                        sendSocketMessage(
+                            code=0,
+                            msg="开始处理详情",
+                            data={
+                                "goods_no": goods_no,
+                                "temp_name": _temp_name,
+                                "status": "进行中",
+                                "goods_art_nos": goods_art_nos,
+                            },
+                            msg_type="detail_progress",
+                        )
                     )
                     all_detail_path_list.append(
                         "{}/详情模板{}/{}".format(out_put_dir, _temp_name, goods_no)
                     )
                     # continue
-                    await self.detail_deal_one_data(
+                    self.detail_deal_one_data(
                         goods_no=goods_no,
                         value=temp_info_data,
                         out_put_dir=out_put_dir,
@@ -1172,7 +1174,7 @@ class RunMain:
         print("text=====>", text)
         return text
 
-    async def detail_deal_one_data(
+    def detail_deal_one_data(
         self,
         goods_no,
         value,
@@ -1186,7 +1188,6 @@ class RunMain:
         # if self.windows.state == 99:
         #     self.show_progress_detail("用户主动取消:{}".format(goods_no))
         #     return
-        await asyncio.sleep(0.01)
         self.show_progress_detail("正在生成:{},模板:{}".format(goods_no, temp_name))
         is_deal_success = False
         print("=================deal_one_data=====================")

+ 1 - 1
python/settings.py

@@ -286,7 +286,7 @@ IS_GET_GREEN_MASK = (
     True if getSysConfigs("other_configs", "is_get_green_mask", "否") == "是" else False
 )  # 是否进行绿幕抠图
 IMAGE_SAVE_MAX_WORKERS = int(
-    getSysConfigs("other_configs", "image_save_max_workers", 4)
+    getSysConfigs("other_configs", "image_save_max_workers", 20)
 )  # 批量保存的线程大小
 COLOR_GRADATION_CYCLES = int(
     getSysConfigs("other_configs", "color_gradation_cycles", 22)

+ 1 - 1
python/sockets/connect_manager.py

@@ -27,7 +27,7 @@ class ConnectionManager:
     async def send_personal_message(self, message: str, websocket: WebSocket):
         '''向用户发送消息'''
         # await websocket.send_json(message)
-        asyncio.create_task(websocket.send_json(message))
+        await websocket.send_json(message)
 
     async def broadcast(self, message: str):
         """广播消息"""

+ 1 - 0
python/sockets/message_handler.py

@@ -64,6 +64,7 @@ async def handlerSend(
     receiveData = json.loads(receiveData)
     # 处理消息发送逻辑
     receiveData = json.loads(receiveData.get("text"))
+    print("receiveData", receiveData)
     jsonType = receiveData.get("type")
     code = receiveData.get("code")
     msg = receiveData.get("msg")

+ 3 - 3
python/sockets/socket_server.py

@@ -21,8 +21,6 @@ smart_shooter = SmartShooter(websocket_manager=conn_manager)
 from utils.common import message_queue
 
 
-
-
 async def updateDataRecord(PhotoFilename, id):
     await asyncio.sleep(0.01)
     create_time = datetime.datetime.fromtimestamp(os.path.getctime(PhotoFilename))
@@ -47,7 +45,6 @@ async def websocket_endpoint(websocket: WebSocket):
     smart_shooter.websocket = websocket
     device_ctrl.websocket = websocket
     blue_tooth.websocket = websocket
-
     # 启动 smart_shooter.connect_listen 服务
     listen_task = None
     tasks = set()
@@ -90,8 +87,11 @@ async def handler_messages(websocket):
             byteDats = await websocket.receive()
             socket_type = byteDats.get("type")
             if socket_type == "websocket.disconnect":
+                print("socket_type===>", byteDats)
                 smart_shooter.stop_listen = True
                 smart_shooter.is_init_while = False
+                if byteDats.get("code") == 1006:
+                    continue
                 device_ctrl.close_connect()
                 device_ctrl.close_lineConnect()
                 device_ctrl.mcu_exit = True