PyQt线程没有运行

时间:2015-06-15 08:49:08

标签: python multithreading qt pyqt

我正在尝试运行一个长期运行的测试套件作为PyQt的后台线程。在osx上,线程永远不会运行,但是在Windows上,如果在启动线程后包含print语句,则线程会运行。代码如下所示:

def runModuleTests(self):
    self.stackedWidget.setCurrentIndex(2)

    self.testThread = QtCore.QThread()
    tr = TestRunner(self.on_testResult, self.moduleArticleNumber, self.moduleSerialNumber, self.testBedArticleNumber)
    tr.moveToThread(self.testThread)
    tr.testFinished.connect(self.testThread.quit)
    self.testThread.started.connect(tr.runModuleTests)
    self.testThread.start()
    print "This print out is here to make threads work.  UGLY HACK!"

我有这些问题:

  • 这个print语句是否导致我的GUI在Windows上产生,所以另一个线程启动了吗?
  • 如何在mac osx和windows上启动线程?
  • GIL是否意味着我无法使用PyQt获得响应式用户界面?
  • 我做错了吗?

我从这个问题的答案中汲取灵感: Background thread with QThread in PyQt

1 个答案:

答案 0 :(得分:0)

来自@Zaiborg的评论是我所遗漏的。即使将对象移动到线程,也需要对对象保持句柄。