[New-bugs-announce] [issue26434] multiprocessing cannot spawn grandchild from a Windows service

Marc Schlaich report at bugs.python.org
Thu Feb 25 04:56:47 EST 2016


New submission from Marc Schlaich:

This is a follow up of #5162.

There are some occasions where you can still run into this issue. One example is if you want to spawn a new multiprocessing.Process as a child of a multiprocessing.Process:

    pythonservice.exe
      - multiprocessing.Process
        - multiprocessing.Process (does not start!)


Attached is a test case. If you run this in pywin32 service debug mode, you see that the process crashes with:

    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 503, in prepare
        file, path_name, etc = imp.find_module(main_name, dirs)
    ImportError: No module named PythonService


In get_preparation_data is the following state:

  WINSERVICE: False
  WINEXE: False
  _python_exe: C:\Python27\python.exe


And so you get as preparation data:

  {'authkey': '...', 'sys_path': [...], 'name': 'test', 'orig_dir': '...', 'sys_argv': ['C:\\Python27\\lib\\site-packages\\win32\\PythonService.exe'], 'main_path': 'C:\\Python27\\lib\\site-packages\\win32\\PythonService.exe', 'log_to_stderr': False}


A workaround for me is patching `get_preparation_data` as follows:

    import multiprocessing.forking

    _org_get_preparation_data = multiprocessing.forking.get_preparation_data

    def _get_preparation_data(*args):
        data = _org_get_preparation_data(*args)
        main_path = data.get('main_path')
        if main_path is not None and main_path.endswith('exe'):
            data.pop('main_path')
        return data

    multiprocessing.forking.get_preparation_data = _get_preparation_data


BTW, the test case does not run on Python 3.5, but starting the service manually did work. So this is probably a Python 2 issue only.

----------
components: Library (Lib), Windows
files: test_mp_service.py
messages: 260846
nosy: paul.moore, schlamar, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: multiprocessing cannot spawn grandchild from a Windows service
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file42025/test_mp_service.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26434>
_______________________________________


More information about the New-bugs-announce mailing list