From 77c9caeb9d7ced394291f521ac3134bd86b2c726 Mon Sep 17 00:00:00 2001
From: shidong <shidong@jhsoft.cc>
Date: 星期六, 12 七月 2025 09:52:54 +0800
Subject: [PATCH] #2025/7/12 #增加日志保存路径的配置 #修改每次只处理最新的记录,去掉线程数量判断,只处理一个

---
 qwen_detect.py |  107 ++++++++++++++++++++++++++---------------------------
 1 files changed, 53 insertions(+), 54 deletions(-)

diff --git a/qwen_detect.py b/qwen_detect.py
index 75249d0..2cd6ab8 100644
--- a/qwen_detect.py
+++ b/qwen_detect.py
@@ -29,26 +29,8 @@
                     value = value.strip()
                     # 灏嗛敭鍊煎娣诲姞鍒板瓧鍏镐腑
                     self.config[key] = value
-        # 閰嶇疆鏃ュ織
-        # 纭繚鏃ュ織鐩綍瀛樺湪
-        log_dir = "logs"
-        os.makedirs(log_dir, exist_ok=True)
-        self.threads: Dict[str, threading.Thread] = {}
-        self.lock = threading.Lock()
-
-        # 鍒濆鍖朚ilvus闆嗗悎
-        connections.connect("default", host=self.config.get("milvusurl"), port=self.config.get("milvusport"))
-        # 鍔犺浇闆嗗悎
-        self.collection = Collection(name="smartobject")
-        self.collection.load()
-        self.pool = qwen_thread(self.config)
-        #鏄惁鏇存柊
-        self._isupdate = False
-
-        # 鍒濆鍖栧叡浜唴瀛�
-        get_mem.smem_init()
-
-        # 閰嶇疆鏃ュ織
+        # 鍒涘缓瀹炰緥涓撳睘logger
+        os.makedirs(self.config.get("logaddr"), exist_ok=True)
         logging.basicConfig(
             level=logging.INFO,
             format='%(asctime)s - %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s: %(message)s',
@@ -56,7 +38,7 @@
             handlers=[
                 # 鎸夊ぇ灏忚疆杞殑鏃ュ織鏂囦欢锛堟渶澶�10MB锛屼繚鐣�3涓浠斤級
                 RotatingFileHandler(
-                    filename=os.path.join(log_dir, 'start_log.log'),
+                    filename=os.path.join(self.config.get("logaddr"), 'qwen_log.log'),
                     maxBytes=10 * 1024 * 1024,  # 10MB
                     backupCount=3,
                     encoding='utf-8'
@@ -65,6 +47,26 @@
                 logging.StreamHandler()
             ]
         )
+        self.logger = logging.getLogger(f"{self.__class__}_{id(self)}")
+        self.logger.setLevel(logging.INFO)
+
+
+        self.threads: Dict[str, threading.Thread] = {}
+        self.lock = threading.Lock()
+
+        # 鍒濆鍖朚ilvus闆嗗悎
+        connections.connect("default", host=self.config.get("milvusurl"), port=self.config.get("milvusport"))
+        # 鍔犺浇闆嗗悎
+        self.collection = Collection(name="smartobject")
+        self.collection.load()
+        #鍒涘缓qwen绾跨▼姹�
+        self.pool = qwen_thread(self.config,self.logger)
+        #鏄惁鏇存柊
+        self._isupdate = False
+
+        # 鍒濆鍖栧叡浜唴瀛�
+        get_mem.smem_init()
+
 
     #鍚姩绾跨▼
     def safe_start(self, target_func, camera_id):
@@ -104,39 +106,36 @@
                 # image_id = get_mem.smem_read_frame_qianwen(camera_id)
                 if len(res_a) > 0:
                     sorted_results = sorted(res_a, key=itemgetter("id"), reverse=True)
-                    # 鏌ヨ鍓峃涓渶澶х殑ID
-                    num = int(self.config.get("threadnum")) - 1
-                    res_a = sorted_results[:num]
-                    for res in res_a:
-                        data = {
-                            "id": res['id'],
-                            "event_level_id": res['event_level_id'],  # event_level_id
-                            "event_level_name": res['event_level_name'],  # event_level_id
-                            "rule_id": res["rule_id"],
-                            "video_point_id": res['video_point_id'],  # video_point_id
-                            "video_point_name": res['video_point_name'],
-                            "is_waning": 0,
-                            "is_desc": 1,
-                            "zh_desc_class": res['zh_desc_class'],  # text_vector
-                            "bounding_box": res['bounding_box'],  # bounding_box
-                            "task_id": res['task_id'],  # task_id
-                            "task_name": res['task_name'],  # task_id
-                            "detect_id": res['detect_id'],  # detect_id
-                            "detect_time": res['detect_time'],  # detect_time
-                            "detect_num": res['detect_num'],
-                            "waning_value": res['waning_value'],
-                            "image_path": res['image_path'],  # image_path
-                            "image_desc_path": res['image_desc_path'],  # image_desc_path
-                            "video_path": res['video_path'],
-                            "text_vector": res['text_vector'],
-                            "knowledge_id": res['knowledge_id'],
-                            "suggestion": res['suggestion'],
-                        }
-                        # logging.info(f"璇诲彇鍥惧儚鎴愬姛: {res['id']}")
-                        # 淇濆瓨鍒癿ilvus
-                        image_id = self.collection.upsert(data).primary_keys
-                        res['id'] = image_id[0]
-                        self.pool.submit(res)
+                    res = sorted_results[0]
+                    data = {
+                        "id": res['id'],
+                        "event_level_id": res['event_level_id'],  # event_level_id
+                        "event_level_name": res['event_level_name'],  # event_level_id
+                        "rule_id": res["rule_id"],
+                        "video_point_id": res['video_point_id'],  # video_point_id
+                        "video_point_name": res['video_point_name'],
+                        "is_waning": 0,
+                        "is_desc": 1,
+                        "zh_desc_class": res['zh_desc_class'],  # text_vector
+                        "bounding_box": res['bounding_box'],  # bounding_box
+                        "task_id": res['task_id'],  # task_id
+                        "task_name": res['task_name'],  # task_id
+                        "detect_id": res['detect_id'],  # detect_id
+                        "detect_time": res['detect_time'],  # detect_time
+                        "detect_num": res['detect_num'],
+                        "waning_value": res['waning_value'],
+                        "image_path": res['image_path'],  # image_path
+                        "image_desc_path": res['image_desc_path'],  # image_desc_path
+                        "video_path": res['video_path'],
+                        "text_vector": res['text_vector'],
+                        "knowledge_id": res['knowledge_id'],
+                        "suggestion": res['suggestion'],
+                    }
+                    # logging.info(f"璇诲彇鍥惧儚鎴愬姛: {res['id']}")
+                    # 淇濆瓨鍒癿ilvus
+                    image_id = self.collection.upsert(data).primary_keys
+                    res['id'] = image_id[0]
+                    self.pool.submit(res)
             except Exception as e:
                 logging.info(f"{camera_id}绾跨▼閿欒:{e}")
             time_sel.sleep(0.01)

--
Gitblit v1.8.0