Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-10-29 01:33:15 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-10-29 03:22:39 +0300
commit52b38d9c3d84485385d5bc2e58f16c5acfaca9b7 (patch)
tree30ec34f5ddcc9a59459df9710c0e763e2d3f1558 /source/blender/python/intern/bpy_interface.c
parent911f9e00d13c57fb093b7ba7b930a340aa0a79a9 (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`. Modified 04c5471ceefb4, setting `sys.executable` instead of using Py_SetProgramName, which is needed for a bundled Python installation.
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r--source/blender/python/intern/bpy_interface.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index c4523363a91..a4417f38756 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -306,7 +306,11 @@ 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. */
+ /* Needed for Python's initialization for portable Python installations.
+ * We could use #Py_SetPath, but this overrides Python's internal logic
+ * for calculating it's own module search paths.
+ *
+ * `sys.executable` is overwritten after initialization to the Python binary. */
{
const char *program_path = BKE_appdir_program_path();
wchar_t program_path_wchar[FILE_MAX];
@@ -354,6 +358,23 @@ void BPY_python_start(bContext *C, int argc, const char **argv)
Py_DECREF(py_argv);
}
+ /* Setting the program name is important so the 'multiprocessing' module
+ * can launch new Python instances. */
+ {
+ char program_path[FILE_MAX];
+ if (BKE_appdir_program_python_search(
+ program_path, sizeof(program_path), PY_MAJOR_VERSION, PY_MINOR_VERSION)) {
+ PyObject *py_program_path = PyC_UnicodeFromByte(program_path);
+ PySys_SetObject("executable", py_program_path);
+ Py_DECREF(py_program_path);
+ }
+ else {
+ fprintf(stderr,
+ "Unable to find the python binary, "
+ "the multiprocessing module may not be functional!\n");
+ }
+ }
+
# ifdef WITH_FLUID
/* Required to prevent assertion error, see:
* https://stackoverflow.com/questions/27844676 */