Search code examples
pythonpython-3.xmultiprocessingpyqt5pyinstaller

PyInstaller executable is not working if using multiprocessing in pyqt5


I was working in my project related to pyqt5 GUI. I used multiprocessing to make it faster. When I run my program in editor, it works fine. But when I converted my program into executable using pyinstaller, then while running the program through this executable, it's not working. GUI opens, but close once it comes to the multiprocessing portion of the code (I get to know this by putting some print statement)

I have also tried mutiprocessing.freeze_support(), still it's not worked.

if I remove the multiprocessing, program through executable works fine, But I need to use multiprocessing to make it faster.

Any suggestion?


Solution

  • I had the same problem a while ago, and I recommend using Nuitka hence it supports Multiprocessing. If the problem lasts, try to use the threading library:

    from threading import Thread
    def worker(a,b):
        while True:
            print(a+b)
            a+=1
    my_thread = Thread(target = worker, args = [10,20])
    my_thread.start()
    

    You can also setup a class if you want to terminate the thread at a certain point.