diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-08-05 12:28:03 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-08-05 12:28:03 +0400 |
commit | aa1477cce1452b117769d1a6614294a3ebfd2314 (patch) | |
tree | 7975face94c0bcf5b30eea4a552a6e1dc68c4f1b /source/blender/python | |
parent | cbb7eefe45e05f7357e60345c119b68e82138e7b (diff) | |
parent | f48631e9a4afb8d7d4ab4e15963b38ba75605f68 (diff) |
https://svn.blender.org/svnroot/bf-blender/trunk/blender, in sync with trunk now
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_driver.c | 17 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_library.c | 3 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 21 |
3 files changed, 32 insertions, 9 deletions
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index bcd5df97c2c..d68fd9a9111 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -41,8 +41,6 @@ #include "bpy_driver.h" -#include "../generic/py_capi_utils.h" - /* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */ PyObject *bpy_pydriver_Dict= NULL; @@ -89,7 +87,7 @@ int bpy_pydriver_create_dict(void) void BPY_driver_reset(void) { PyGILState_STATE gilstate; - int use_gil= !PYC_INTERPRETER_ACTIVE; + int use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */ if(use_gil) gilstate= PyGILState_Ensure(); @@ -120,9 +118,14 @@ static void pydriver_error(ChannelDriver *driver) /* This evals py driver expressions, 'expr' is a Python expression that * should evaluate to a float number, which is returned. * - * note: PyGILState_Ensure() isnt always called because python can call the - * bake operator which intern starts a thread which calls scene update which - * does a driver update. to avoid a deadlock check PYC_INTERPRETER_ACTIVE if PyGILState_Ensure() is needed. + * (old)note: PyGILState_Ensure() isnt always called because python can call + * the bake operator which intern starts a thread which calls scene update + * which does a driver update. to avoid a deadlock check PYC_INTERPRETER_ACTIVE + * if PyGILState_Ensure() is needed - see [#27683] + * + * (new)note: checking if python is running is not threadsafe [#28114] + * now release the GIL on python operator execution instead, using + * PyEval_SaveThread() / PyEval_RestoreThread() so we dont lock up blender. */ float BPY_driver_exec(ChannelDriver *driver) { @@ -149,7 +152,7 @@ float BPY_driver_exec(ChannelDriver *driver) return 0.0f; } - use_gil= !PYC_INTERPRETER_ACTIVE; + use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */ if(use_gil) gilstate= PyGILState_Ensure(); diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c index 85bffb5a8cc..4ce3e0356e2 100644 --- a/source/blender/python/intern/bpy_library.c +++ b/source/blender/python/intern/bpy_library.c @@ -39,6 +39,7 @@ #include "BKE_library.h" #include "BKE_idcode.h" #include "BKE_report.h" +#include "BKE_context.h" #include "BLI_utildefines.h" #include "BLI_string.h" @@ -317,7 +318,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) flag_all_listbases_ids(LIB_PRE_EXISTING, 1); /* here appending/linking starts */ - mainl= BLO_library_append_begin(BPy_GetContext(), &(self->blo_handle), self->relpath); + mainl= BLO_library_append_begin(CTX_data_main(BPy_GetContext()), &(self->blo_handle), self->relpath); { int i= 0, code; diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index b8883e655f2..4a17c45ae38 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -55,6 +55,10 @@ #include "BKE_report.h" #include "BKE_context.h" +/* so operators called can spawn threads which aquire the GIL */ +#define BPY_RELEASE_GIL + + static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) { wmOperatorType *ot; @@ -219,7 +223,22 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList"); BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD); /* own so these dont move into global reports */ - operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports); +#ifdef BPY_RELEASE_GIL + /* release GIL, since a thread could be started from an operator + * that updates a driver */ + /* note: I havve not seen any examples of code that does this + * so it may not be officially supported but seems to work ok. */ + { + PyThreadState *ts= PyEval_SaveThread(); +#endif + + operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports); + +#ifdef BPY_RELEASE_GIL + /* regain GIL */ + PyEval_RestoreThread(ts); + } +#endif error_val= BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE); |