【发布时间】:2015-01-06 02:59:42
【问题描述】:
我有 GUI 应用程序,它使用 qwebview 通过长循环进行网络自动化过程,所以我使用 QThread 来执行此操作,但我无法终止线程,我的代码如下
class Main(QMainWindow):
def btStart(self):
self.mythread = BrowserThread()
self.connect(self.mythread, SIGNAL('loop()'), self.campaign_loop, Qt.AutoConnection)
self.mythread.start()
def btStop(self):
self.mythread.terminate()
def campaign_loop(self):
loop goes here
class BrowserThread(QThread):
def __init__(self):
QThread.__init__(self)
def run(self):
self.emit(SIGNAL('loop()'))
这段代码在启动线程时工作正常,但无法停止循环,浏览器仍在运行,即使我调用它的关闭事件并且它从 GUI 中消失
【问题讨论】:
标签: python pyside qthread terminate