Python 在pyqt上执行多个线程
我正在尝试执行两个并发过程,第一个过程不断计算,例如,每0.1秒计算一次麦克风记录的频率,而第二个过程每0.5秒计算一次频率并绘制一个表示 我对如何实现线程有点困惑,我不能执行并行线程 下面是一段代码:Python 在pyqt上执行多个线程,python,multithreading,pyqt,Python,Multithreading,Pyqt,我正在尝试执行两个并发过程,第一个过程不断计算,例如,每0.1秒计算一次麦克风记录的频率,而第二个过程每0.5秒计算一次频率并绘制一个表示 我对如何实现线程有点困惑,我不能执行并行线程 下面是一段代码: class MicrophoneThread(QtCore.QThread): def __init__(self): super(MicrophoneThread , self).__init__() def __del__(self): se
class MicrophoneThread(QtCore.QThread):
def __init__(self):
super(MicrophoneThread , self).__init__()
def __del__(self):
self.wait()
def run(self):
print("Microphone Thread")
while True:
time.sleep(0.1)
self.emit(SIGNAL('listen()'))
class PaintThread(QtCore.QThread):
def __init__(self, el):
super(PaintThread , self).__init__(el)
def __del__(self):
self.wait()
def run(self):
i = 0
while True:
i += 1
time.sleep(0.5)
self.emit(QtCore.SIGNAL('update(QString)'), str(i))
我从主窗口实例化线程
threadOne = MicrophoneThread(self)
self.connect(threadOne , QtCore.SIGNAL('listen()') , self.listen, Qt.DirectConnection)
threadOne.start()
threadTwo = PaintThread(self)
self.connect(threadTwo , QtCore.SIGNAL('update(QString)') , self.changeIndicatorAngle, Qt.DirectConnection)
self.connect(threadTwo , QtCore.SIGNAL('update(QString)') , self.changeNoteLabel, Qt.QueuedConnection)
threadTwo.start()
只有MicrophoneThread启动,而第二个线程不工作
任何需要阅读的建议或文件都将不胜感激。我自己解决了这个问题,问题很简单 当程序启动时,我在主窗口中实例化第一个线程,而只有在单击另一个窗体上的按钮时,我才实例化第二个线程 因此,我有一个主窗口,在其中运行MicrophoneThread,还有一个窗体,当我单击按钮时,在其中运行PaintThread