This is almost the same as this question , but the given solution there (calling freeze_support ()) does not work for me.
I have the following script called start.py which I use to create a standalone executable with py2exe (version 0.9.2.2). I also have python.exe in the same directory.
import multiprocessing def main(): print('Parent') p = multiprocessing.Process(target=new_process) multiprocessing.set_executable('python.exe') p.start() p.join() def new_process(): print('Child') if __name__ == '__main__': multiprocessing.freeze_support() main()
It works great on startup like pure python. However, when it is packaged as an executable, this is the error I get:
Unknown option: -- usage: <path to start.exe> [option] ... [-c cmd | -m mod | file | -] [arg] ... Try `python -h' for more information.
This is clearly caused by a call.
python.exe --multiprocessing-fork
If I do not call set_executable () and freeze_support (), the child process simply starts exe and starts as __main__, causing an endless chain of new processes to print "Parent", while "Child" is never printed.
The only thing that calls the freeze_support () function is to make the child process throw the following error if I don't call multiprocessing.set_executable ()
Traceback (most recent call last): File "start.py", line 17, in <module> multiprocessing.freeze_support() File "C:\Python34\Lib\multiprocessing\context.py", line 148, in freeze_support freeze_support() File "C:\Python34\Lib\multiprocessing\spawn.py", line 67, in freeze_support main() NameError: name 'main' is not defined
I am using the 32-bit version of Python 3.4 for the 64-bit version of Windows 8.1. I tried all the above using cx-freeze with the same results. Any help would be greatly appreciated.
EDIT: Even if this example is straight from the docs :
from multiprocessing import Process, freeze_support def f(): print('hello world!') if __name__ == '__main__': freeze_support() Process(target=f).start()
I get the same nameError when the child process calls freeze_support ().