How to use multiprocessing with GUI and backend classes?

Stack Overflow Asked by ggokturk on August 17, 2020

I have a script which contains GUI and backend part. Briefly, you can see the summary of code below

class GUI():
    def __init__(self):

    def initUI(self):
        ... elements... buttons etc.
    def clickedButton(self):

class Backend():
    def __init__(self):

    def do_something1(self):
    def do_something2(self,x,y):
    def thread(self,x,y):
        threading.Thread(target = self.do_something2(), args=(self,x,y)).start()

    def pool():
        p = Pool(processes=5)
        p.starmap(self.thread, items)

if __name__ == '__main__':
   import sys
   from multiprocessing import Pool
   import threading
   ex  = GUI()

My code normally working well. But I want to do some works in parallel to speed up the algorithm. I know it is looking messy and something can be missing. I am apologizing for this. Mainly, I want to create 5 worker or more to run in parallel. So thread funcion in backend class work 5 times with different arguments that I defined in pool function basicly. When user clicked the button in GUI, it should be run 5 times backend class with different arguments. I am open for any advise.

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP