PyQt5线程启动和停止

问题描述

现在我正在研究一种方法来启动和停止正在运行的线程,但是我遇到了一些问题,因为Qrunnable每次调用PyQt5.QtCore.QThreadPool().start()时都会启动自己的线程,我想知道是否有办法使用PyQt5暂停并恢复该线程。

示例代码:

self.threadpool = PyQt5.QtCore.QThreadPool()
if self.start_button.text() == "Start": 
   self.threadpool.start(xStart("hello",True))
   self.start_button.setText("Stop")
else:
   self.start_button.setText("Start")
   self.threadpool.deamon(xStart("hi",False))

class xDemo(PyQt5.QtCore.QRunnable):
    def __init__(self,text,start):
        super(xDemo,self).__init__()
        self.text = text
        self.start = start

    @PyQt5.QtCore.pyqtSlot()
    def run(self):
        """
        """
        while self.start == True:
            print(self.text)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)