当 QThread 包含 PyAudio() 流时,PySide2 和 PySide6 GUI 会冻结,而 PyQt5 运行良好这是一个错误吗?

问题描述

使用 pyside2PySide6 时,在 PyAudio 中打开 QThread 流时,许多与 GUI 和网络浏览器相关的操作将导致 {{ 1}} 冻结。

但是使用 GUI 和相同的代码不会遇到任何问题。我想知道这是 PyQt5错误吗?

我在 PySide 上运行它,使用 Windows10pyside2(5.15.0)PySide6(6.0.0)

代码如下:

PyQt5(5.15.0)

运行后,先点击import sys,pyaudio from pyside2.QtCore import * from pyside2.QtWidgets import * from pyside2.QtGui import * import threading,webbrowser class MainWindow(QMainWindow): def __init__(self): super().__init__() widget = Widget() self.setCentralWidget(widget) self.show() class Widget(QWidget): def __init__(self): super().__init__() self.btn1 = QPushButton('''Open Being''') self.btn1.clicked.connect(lambda: webbrowser.open('https://www.bing.com')) self.btn2 = QPushButton('''Get pyaudio''') self.btn2.clicked.connect(self.getPyaudioThread) layout = QVBoxLayout() layout.addWidget(self.btn1) layout.addWidget(self.btn2) self.setLayout(layout) def getPyaudioThread(self): self.pyaudioThread = PyaudioThread() self.pyaudioThread.start() class PyaudioThread(QThread): CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 16000 def __init__(self): super().__init__() def record(self,stream): while True: stream.read(self.CHUNK) def run(self): self.p = pyaudio.PyAudio() stream = self.p.open(channels=self.CHANNELS,format=self.FORMAT,rate=self.RATE,input=True,frames_per_buffer=self.CHUNK) # threading.Thread(target=self.record,args=[stream]).start() print('pyaudio required') def main(): app = QApplication(sys.argv) mainWindow = MainWindow() sys.exit(app.exec_()) if __name__ == '__main__': main() 按钮,然后点击Get pyaudio按钮,然后整个Open Being都会冻结。

解决方法

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

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

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