ボタンをクリックしてボタンを作成してマルチプロセッシングを実行しようとしましたが、PyQtからマルチプロセッシングを正しく実行するにはどうすればよいですか?
がUIにブロックされます。私はバックゴンドでプロセスを実行することを願っています。私はそれを修正するにはどうすればよい
?
from PySide2 import QtCore,QtGui,QtWidgets
import sys
import multiprocessing
from threading import Timer
class TTT(multiprocessing.Process):
def __init__(self):
super(TTT, self).__init__()
self.daemon = True
def run(self):
while True:
t = Timer(5, self.doSomething)
t.start()
t.join()
def doSomething(self):
try:
print('123')
except Exception as e:
print(e)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
btn = QtWidgets.QPushButton('run process')
btn.clicked.connect(self.create_process)
self.setCentralWidget(btn)
def create_process(self):
QtWidgets.QMessageBox.information(self,'hhh','hhh')
t = TTT()
t.start()
t.join()
if __name__=="__main__":
app=QtWidgets.QApplication(sys.argv)
ex = MainWindow()
ex.show()
sys.exit(app.exec_())
Qtフレームワークを使用している場合は、Qtと標準のPythonを混ぜる代わりに、Qtの機能を使用することをお勧めします。信号とthredingはQtで私のために素晴らしいようです:) –
あなたはQThreadを使用することを意味しますか? –
QThreadは単なるオプションの1つです。 –