GUI main 部分,主app類中的__init__初始化方法中添加
實例化線程
self.s2_thread=Worker2()
初始化一個定時器
self.log_get=QtCore.QTimer()
將調用方法和信號綁定
QtCore.QObject.connect(self.s2_thread, QtCore.SIGNAL("get_log_start()"), self.qtimer_get_log)
定義觸發開始的調用方法
def qtimer_get_log(self):
self.log_get.singleShot(30000,self.s2_thread.get_mem_error_logfile_content) self.log_get.singleShot(90000,self.s2_thread.get_mem_right_logfile_content)
self.log_get.start()
線程Qthread部分
在線程的run中根據需要的地方發起激活定時器的信號
class Worker2(QtCore.QThread): def __init__(self, parent=None): QtCore.QThread.__init__(self, parent)
def get_mem_error_logfile_content(self):
filename=host_list['app75']['autologfilename']
with open(filename,'r') as f:
self.log_30_sec=f.read()
print '#'*30
def get_mem_right_logfile_content(self):
filename=host_list['app75']['autologfilename']
with open(filename,'r') as f:
self.log_90_sec=f.read()
print '*'*30 def run(self): ...... self.emit(QtCore.SIGNAL("get_log_start()")) #觸發定時器信號 ......
