1

I am trying to write a program with multiprocessing and PyQt5. The processes start and run, but the application window does not respond at all. The data in the window is not updated. Also, the exit button does not work. The window just hangs. How can I update data in it, for example, display a process counter? And make an exit or pause.

class mywindow(QtWidgets.QMainWindow):
        def __init__(self):
            super(mywindow, self).__init__()
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
            self.ui.pushButton.clicked.connect(self.btnClicked)
            self.ui.pushButton_2.clicked.connect(self.btn2Clicked)

        def btn2Clicked(self):
            sys.exit(app.exec()) # <=== This does not work


        def btnClicked(self):

            with urllib.request.urlopen(url) as f:
                proxy = f.read().decode('utf-8')
                f.close()
                proxy = json.loads(proxy)
                proxy = proxy['data']
                for i in proxy:
                    print(i['proxy'])
                    proxy_list.append(i)

            proxy_list_len = len(proxy_list)
            print(proxy_list_len)
            cnt = 0
            threads = 300

            with Manager() as manager:
                bad_proxy_list = manager.list()
                good_proxy_list = manager.list()
                processes = []
                while cnt < proxy_list_len:
                    for i in range(threads):
                        p = Process(target=multi, args=(proxy_list[cnt], good_proxy_list, bad_proxy_list))
                        p.start()
                        processes.append(p)
                        cnt += 1
                        if cnt >= proxy_list_len:
                            break
                        print(cnt)
                    for p in processes:
                        print(p)
                        p.join()
                    self.ui.label_2.setText(str(cnt)) # <=== This does not work

Mmm
  • 11
  • 1
  • You should use QThread and QThreadPool. See e.g. https://stackoverflow.com/questions/45211218/multi-threading-in-pyqt-5 or https://stackoverflow.com/questions/9957195/updating-gui-elements-in-multithreaded-pyqt and references therein – Demi-Lune Apr 12 '20 at 09:04

0 Answers0