I have written python scripts, that are deployed by setuptools. I use multiprocess.Process inside these scripts, but if i start the deployed script it fails with this error message:

Traceback (most recent call last):
  File "C:\Python34\Scripts\process_demo.py", line 4, in <module>
    __import__('pkg_resources').run_script('procdemo==1.0', 'process_demo.py')
  File "C:\Python34\lib\site-packages\setuptools-5.4.1-py3.4.egg\pkg_resources.py", line 534, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "C:\Python34\lib\site-packages\setuptools-5.4.1-py3.4.egg\pkg_resources.py", line 1445, in run_script
    "Can't perform this operation for unregistered loader type"
  File "C:\Python34\lib\site-packages\procdemo-1.0-py3.4.egg\EGG-INFO\scripts\process_demo.py", line 19, in <module>
  File "C:\Python34\lib\site-packages\procdemo-1.0-py3.4.egg\EGG-INFO\scripts\process_demo.py", line 14, in main
  File "C:\Python34\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Python34\lib\multiprocessing\context.py", line 212, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Python34\lib\multiprocessing\context.py", line 313, in _Popen
    return Popen(process_obj)
  File "C:\Python34\lib\multiprocessing\popen_spawn_win32.py", line 34, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Python34\lib\multiprocessing\spawn.py", line 173, in get_preparation_data
    main_mod_name = getattr(main_module.__spec__, "name", None)
AttributeError: 'module' object has no attribute '__spec__'

I created a short test file with nothing more than the call of multiprocessing.Process and the problem is obviously there.

process_demo.py

import multiprocessing

def worker():
    print("foooo")

def main(threads=4):
    procs = []

    for i in range(threads):
        p = multiprocessing.Process(target=worker)
        procs.append(p)
        p.start()

if __name__ == "__main__":
    multiprocessing.freeze_support()
    main()

The Setup File:

from ez_setup import use_setuptools
use_setuptools()

from setuptools import setup

setup(name='procdemo',
      version='1.0',
      description='Some Demo',
      scripts=['bin/process_demo.py'],
      )

How can i safely start Processes inside a script without breaking the setuptools?

share|improve this question
up vote 1 down vote accepted

I'm not sure if there is another way but if you build out of the python script a console application it works without any problem:

from ez_setup import use_setuptools
use_setuptools()

from setuptools import setup

setup(name='procdemo',
      version='1.0',
      description='Some Demo',
      scripts=['bin/process_demo.py'],
      entry_points = {'console_scripts': ['foobarfoo = process_demo:main']},
      )
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.