在PyQt5 中使用多进程

from multiprocessing import Process, Queue
from PyQt5 import ...

class communicate_Thread(QThread):

    communicate_singal = pyqtSignal(str)
    exit_signal = pyqtSignal()

    def __init__(self, q, parent=None,):
        QThread.__init__(self, parent)
        self.q = q

    def run(self):
        global running
        while(running):
            text = self.q.get(True)
            self.communicate_singal.emit(text)

        self.exit_signal.emit()

class App(QMainWindow):
    def __init__(self):
        .....
        self.q = Queue()
        self.xxx = communicateThread(self.q)
        self.xxx.communicate_singal.connect(self.do_something)
        self.xxx.start()
        
        self.yyy_process = Process(target=self.yyyprocess, args=(self.q,))
        self.yyy_process.start()
        
    def yyyprocess(self,q):
        do_something
        if condition:
            q.put(something)

你可能感兴趣的:(在PyQt5 中使用多进程)