Skip to content

Commit

Permalink
fix: race
Browse files Browse the repository at this point in the history
  • Loading branch information
sqzw-x committed Oct 22, 2024
1 parent 5de2804 commit 667f106
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/models/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
依赖:
此模块不应依赖除 models.base.utils 外的任何项目代码
"""
import threading
import time

from PyQt5.QtCore import QObject, pyqtSignal
Expand Down Expand Up @@ -36,24 +37,23 @@ class Signals(QObject):
# endregion
def __init__(self):
super().__init__()
self.log_lock = threading.Lock()
self.detail_log_list = []
self.stop = False

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):
Expand Down

0 comments on commit 667f106

Please sign in to comment.