Как использовать многопроцессорную очередь () для связи с супроцессом в QYQT5? - PullRequest
0 голосов
/ 21 апреля 2020

Могут ли некоторые, пожалуйста, взглянуть. Интересно, что QYQT5 GUI не поддерживает Queue () между подпроцессами. если я не использую Queue (), нет проблем. Но я должен использовать Queue () для связи каждого подпроцесса. Пожалуйста, помогите мне ~~~ !!

  • То, что я хочу сделать, просто.

    1. В QYQT5 GUI, если я нажимаю кнопку, многопроцессорность Создано 2 подпроцесса.
    2. Затем с помощью Queue () 2 подпроцесса связываются друг с другом.
  • Мой код не работает.

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from multiprocessing import Process, Queue 

def worker(processing_queue):
    print("put")
    processing_queue.put(1)

def consumer(processing_queue):
    print("read")
    processing_queue.get()

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("my window")
        self.setGeometry(100, 100, 320, 300)

        #creating a button to be clicked
        button1 = QPushButton('Button-1', self)
        button1.move(100, 70)
        button1.clicked.connect(self.on_click)      # button1

    @pyqtSlot()
    def on_click(self):  

        processing_queue = Queue()    # This is not working, I want to communicate between subprocess using Queue()

        p1 = Process(target=worker, args=(processing_queue)) # not working...
        p1.start()

        p2 = Process(target=consumer, args=(processing_queue)) # not working...
        p2.start()

        print('testing....')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    ex.show()
    sys.exit(app.exec_())

...