Search code examples
pythonmultiprocess

Pythons Multiprocess on Windows in a Package


I am trying to use multiprocess on windows but I am encountering the infinite loop error. Now I know this can be fixed by using the name == "main" in a standard python script. My problem is I am packaging the script so name is equal to "testmultiprocess" (The package name).

I have created a small project on github to demonstrate my issue as it requires multiple files and an install.

Thanks, Niall

Edit:

test.py:

from multiprocessing import Process, Queue

def testFunction():
    print "testFunction"

def main():
    print __name__
    p = Process(target=testFunction)
    p.start()
    p.join()

name that is printed is allways "testmultiprocessing" as it is the package name


Solution

  • I managed to fix this by patching the script created in the python directory that runs my package.

    C:\Python27\Scripts\testmultiprocess-script.py

    from:

    sys.exit(
        load_entry_point(.....)
    )
    

    to:

    if __name__ == '__main__':
     sys.exit(
         load_