diff --git a/src/models/signals.py b/src/models/signals.py index e602801..f6c4a5c 100644 --- a/src/models/signals.py +++ b/src/models/signals.py @@ -7,6 +7,7 @@ 依赖: 此模块不应依赖除 models.base.utils 外的任何项目代码 """ +import threading import time from PyQt5.QtCore import QObject, pyqtSignal @@ -36,6 +37,7 @@ class Signals(QObject): # endregion def __init__(self): super().__init__() + self.log_lock = threading.Lock() self.detail_log_list = [] self.stop = False @@ -43,17 +45,15 @@ def add_log(self, *text): if self.stop: raise '手动停止刮削' try: - self.detail_log_list.append(f" ⏰ {time.strftime('%H:%M:%S', time.localtime())} {' '.join(text)}") + with self.log_lock: + self.detail_log_list.append(f" ⏰ {time.strftime('%H:%M:%S', time.localtime())} {' '.join(text)}") except: pass def get_log(self): - text = '' - if self.detail_log_list: - a = len(self.detail_log_list) - text = '\n'.join(self.detail_log_list[:a]) - for _ in range(a): - self.detail_log_list.pop(0) + with self.log_lock: + text = '\n'.join(self.detail_log_list) + self.detail_log_list = [] return text def show_traceback_log(self, text):