pyqt如何用多线程解决卡顿问题

pyqt如何用多线程解决卡顿问题

from PyQt5.QtWidgets import *
from function import bigFunction
from multiprocessing import Process

'''
pyqt如何用多线程解决卡顿问题
我尝试运行如下代码,但是 bigFunction 未能成功运行
需要使用多进程解决

一个很初级的问题,我该如何更改
'''


def do():
    p = Process(target=bigFunction)
    # bigFunction 是一个耗时且会导致程序未响应的方法
    p.start()

class setElement(QWidget):
    def func(self):
        print('click')
    def __init__(self):
        super(QWidget, self).__init__()
        self.setStyleSheet('')
        self.button = QPushButton(self)
        self.button.setText('click')
        self.button.setGeometry(100,50,100,30)
        self.button.clicked.connect(self.func)
        self.button2 = QPushButton(self)
        self.button2.setText('someText')
        self.button2.setGeometry(100,230,100,30)
        self.button2.clicked.connect(do)
        self.show()


APP = QApplication([])
e =setElement()
APP.exec_()

多线程你应该使用qthread。你使用Process只是不会让ui界面卡住。将耗时的函数放到qthread里去处理。ui始终不要被阻塞

Process是进程,不是线程
你可以使用threading,也可以使用threadingpool
然后多线程执行结果你可以写个委托操作ui显示
你搞好多进程,那变成黑箱了

bigFunction是你自己写的么?python有function库,但是function库没有bigFunction