Trying to implement multiprocessing within a PyQt5 GUI framework to process multiple files in a parallel process, preferably in a QThread() background. Running the code below seems to create the multiple processes but has additional issue that multiple GUI windows appear and everything seems locked out at that point.
import multiprocess as mp
from PyQt5.QtWidgets import QMainWindow
class MyApp(QMainWindow, myUiMainWindow):
def __init__(self):
super(self.__class__, self).__init()
self.setupUI(self)
self.pushButton.clicked.connect(self.doMyStuff)
def consumer(self, inQ, outQ):
val = inQ.get()
ret = self.process_single(val)
outQ.put(ret)
def process_single(self, f):
<process each file f>
<update progress bar>
return f
def doMyStuff(self):
<get file_list from GUI Widget>
n_w = len(file_list) if len(file_list) < 5 else 5
inQ = mp.Queue()
outQ = mp.Queue()
workers = [mp.Process(target=consumer, args=(inQ, outQ) for i in range(n_w)]
[w.start() for w in workers]
[inQ.put(f) for f in file_list]
[inQ.put(None) for i in range(n_w)]
completed_files = []
while len(completed_files) != len(file_list):
completed_files.append(outQ.get())
[w.join() for w in workers]
Guess what...
implement the following to build the GUI only once:
... you probably figured this one out by now ;p