question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wheel: script with multiprocessing doesn't work on Windows

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
jenisyscommented, Oct 27, 2015

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) !?!

0reactions
dstufftcommented, Mar 24, 2017

Closing this, this is a bug with Python itself and it appears fixed in 3.x and 2.7.111 so the recommendation is to get a newer Python if you are hitting this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiprocessing python within frozen script - Stack Overflow
The documentation linked above has an easy fix that redirects all outputs to files. import sys sys.stdout = open(“my_stdout.log”, “w”) sys.
Read more >
How to get Python multiprocessing module working on ...
I managed to get multi-processing working on ms-windows, doing some workarounds. sys.executable needs to point to Python executable. The scripts __file__ ...
Read more >
Advanced Topics — PyArmor 7.2.0 documentation
Almost all the obfuscated scripts will be run as main script; In the obfuscated scripts call multiprocessing to create new process; Or call...
Read more >
Multithreading PyQt5 applications with QThreadPool
Run background tasks concurrently without impacting your UI. A common problem when building Python GUI applications is.
Read more >
Installing Ray — Ray 2.2.0 - the Ray documentation
Ray on Windows is currently in beta. Official Releases#. From Wheels#. You can install the latest official version of Ray from PyPI on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found