简体   繁体   中英

Error when running a .exe file using Python multiprocessing

I recently dabbled with multiprocessing in one of my python projects.

I would run my script in my terminal and everything would run flawlessly. However, when I turned the .py script into a .exe using pyinstaller it wouldn't work anymore.

I've narrowed it down to the issue being the Manager() method.

Consider the following piece of code:

from multiprocessing import Manager

if __name__ == '__main__':
    print("Starting")
    manager = Manager()
    print("Worked")

Running the script as a .py file outputs:
> Starting
> Worked

After converting to a .exe the script outputs Starting continuously:
> Starting
> Starting
> Starting
etc...

I managed to snatch this error code after performing a keyboardinterrupt on the running code if any help.

Please let me know if you guys encounter the same issue, or have any idea how to fix this. Have a great weekend <3

Thank you so much gddc all I had to do was
import an extra method
and add an extra command
The code now looks like this:

from multiprocessing import Manager, freeze_support

if __name__ == '__main__':
    freeze_support()
    print("Starting")
    manager = Manager()
    print("Worked")

<kite.com/python/docs/multiprocessing.freeze_support>

The thing is...pyinstaller has a lot of problems. In fact, most modules for converting .py files to .exe do. To be honest, I don't really think it's a problem with multiprocessing, but it might be. I suggest maybe trying other modules to convert .py to .exe , like cx_freeze or auto_py_to_exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM