This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author schlamar
Recipients paul.moore, schlamar, steve.dower, tim.golden, zach.ware
Date 2016-02-25.09:56:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1456394207.49.0.123218861266.issue26434@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-02-25 09:56:47schlamarsetrecipients: + schlamar, paul.moore, tim.golden, zach.ware, steve.dower
2016-02-25 09:56:47schlamarsetmessageid: <1456394207.49.0.123218861266.issue26434@psf.upfronthosting.co.za>
2016-02-25 09:56:47schlamarlinkissue26434 messages
2016-02-25 09:56:46schlamarcreate