multiprocessing and freezing on Windows

S

SK

Is there a method for freezing a Python 2.6 app using multiprocessing
on Windows using PyInstaller or py2exe that works? It is trying to
call my executable instead of python.exe when the process starts and
passes it --multiprocessing-fork . Adding a freeze_support() to my
main doesn't help. Do I have to bundle all of Python and use
set_executable() to point to the bundled python.exe? I can't find any
workable information on the canonical way to do this.

Thanks!
 
S

SK

To add a bit more information, I found that I needed to patch
get_command_line in multiprocessing/forking.py replacing:

if getattr(sys, 'frozen', False):
return [sys.executable, '--multiprocessing-fork']
else:
prog = 'from multiprocessing.forking import main; main()'
return [_python_exe, '-c', prog, '--multiprocessing-fork']

with:

if WINEXE:
prog = 'from multiprocessing.forking import main; main()'
return [_python_exe, '-c', prog, '--multiprocessing-fork']
elif getattr(sys, 'frozen', False):
return [sys.executable, '--multiprocessing-fork']
else:
prog = 'from multiprocessing.forking import main; main()'
return [_python_exe, '-c', prog, '--multiprocessing-fork']

and then using py2exe I can get a working "frozen" package if I
include pythonw.exe and a subset of Python's Lib directory in my
package and call multiprocessing.set_executable to point to that
pythonw.exe.

Does the above patch address a real bug?

Is packaging with multiprocessing supposed to be this hard? If so,
some documentation is needed.
 
G

Gabriel Genellina

To add a bit more information, I found that I needed to patch
get_command_line in multiprocessing/forking.py [...]

Is packaging with multiprocessing supposed to be this hard? If so,
some documentation is needed.

Shouldn't be so hard, I presume. You may want to post your comments and
upload the patch to http://bugs.python.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top