diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-10-28 03:31:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-10-28 03:49:29 +0300 |
commit | 04c5471ceefb41c9e49bf7c86f07e9e7b8426bb3 (patch) | |
tree | 17302a73e2d0aa0399506cc9d41aaa567c68c5a7 /source/blender/python/intern/bpy_interface.c | |
parent | bee5921e82eb32dfc2c64aa063f991bc36faa5c7 (diff) |
PyAPI: point sys.executable to the Python binary
`sys.executable` is documented to be a Python interpreter or None.
This was set to Blender's executable which caused the multiprocessing
module to spawn new instances of Blender instead of Python on WIN32.
See issue described in D7815.
Deprecate 'bpy.app.binary_path_python' & warn when using.
Blender's executable remains accessible via `bpy.app.binary_path`.
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index c4523363a91..894a9a69198 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -306,12 +306,22 @@ void BPY_python_start(bContext *C, int argc, const char **argv) PyThreadState *py_tstate = NULL; const char *py_path_bundle = BKE_appdir_folder_id(BLENDER_SYSTEM_PYTHON, NULL); - /* Not essential but nice to set our name. */ + /* Setting the program name is important so the 'multiprocessing' module + * can launch new Python instances. */ { - const char *program_path = BKE_appdir_program_path(); - wchar_t program_path_wchar[FILE_MAX]; - BLI_strncpy_wchar_from_utf8(program_path_wchar, program_path, ARRAY_SIZE(program_path_wchar)); - Py_SetProgramName(program_path_wchar); + char program_path[FILE_MAX]; + if (BKE_appdir_program_python_search( + program_path, sizeof(program_path), PY_MAJOR_VERSION, PY_MINOR_VERSION)) { + wchar_t program_path_wchar[FILE_MAX]; + BLI_strncpy_wchar_from_utf8( + program_path_wchar, program_path, ARRAY_SIZE(program_path_wchar)); + Py_SetProgramName(program_path_wchar); + } + else { + fprintf(stderr, + "Unable to find the python binary, " + "the multiprocessing module may not be functional!\n"); + } } /* must run before python initializes */ |