pip: wheel: script with multiprocessing doesn't work on Windows

setup.py

from setuptools import setup

setup(
    version='0.0.1',
    name="blub",
    py_modules=["blub"],
    entry_points={
        'console_scripts': ['blub = blub:main'],
    },
)

blub.py

import multiprocessing

def f():
    pass

def main():
    p = multiprocessing.Process(target=f)
    p.start()
    p.join()
    print 'xxx'

When installing this without wheel, everything is fine:

$ pip install .
$ blub
xxx

Installing this as wheel, the script is broken:

$ pip uninstall blub
$ pip wheel .
$ pip install wheelhouse/*
$ blub
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\Python27\Lib\multiprocessing\forking.py", line 380, in main
    prepare(preparation_data)
  File "c:\Python27\Lib\multiprocessing\forking.py", line 488, in prepare
    assert main_name not in sys.modules, main_name
AssertionError: __main__
xxx

This is probably related to http://bugs.python.org/issue10845.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

PIP-VERSION: 7.1.2 SETUPTOOLS-VERSION: 18.4

This problem is not related to wheel-based installations. This problem exists also when you install a source distribution from a ZIP file. The problem seems to be caused how the <script>.exe is created in the “Scripts/” sub-directory. A __main__.py is archived/embedded in the <script>.exe executable. Probably the sys.executable from __main__.py is not resolved correctly when the multiprocessing.forking module is involved.

WORKAROUNDS (alternatives):

  1. Install package with easy_install (setuptools) and everything is fine.
  2. Put a python script ala <script>.py in the “Scripts/” directory and everything is fine.

EXAMPLE:

  1. Checkout Github repository: https://github.com/cgoldberg/multi-mechanize
  2. Create a virtual environment and install multi-mechanize from checkout repository.
  3. Execute “multimech-run.exe examples”

MAYBE: multiprocessing.set_executable(...) is needed in scripts that use multiprocessing (on Windows) !?!