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:
authorSybren A. Stüvel <sybren@blender.org>2021-09-09 15:27:00 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-09 15:27:33 +0300
commitfc460351170478e712740ae1917a2e24803eba3b (patch)
treeab6e7e60760fa1f3b76ade2f85468246603e1c7b
parentda50cd86a745c9e63fc645bad6f0a5412afff920 (diff)
Depsgraph: release GIL when evaluating the depsgraph
Evaluating the dependency graph potentially executes Python code when evaluating drivers. In specific situations (see T91046) this could deadlock Blender entirely. Temporarily releasing the GIL when evaluating the depsgraph resolves this. Calling the `BPy_BEGIN_ALLOW_THREADS` macro is relatively safe, as it's a no-op when the current thread does not have the GIL. Developed in collaboration with @sergey Manifest task: T91046
-rw-r--r--source/blender/depsgraph/CMakeLists.txt7
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval.cc13
2 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index 3ad26c6f4db..41253117096 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -161,6 +161,13 @@ set(LIB
bf_blenkernel
)
+if(WITH_PYTHON)
+ add_definitions(-DWITH_PYTHON)
+ list(APPEND INC
+ ../python
+ )
+endif()
+
blender_add_lib(bf_depsgraph "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
if(WITH_GTESTS)
diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc
index ad88cf656ad..c816c7b8db5 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval.cc
@@ -41,6 +41,10 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
+#ifdef WITH_PYTHON
+# include "BPY_extern.h"
+#endif
+
#include "atomic_ops.h"
#include "intern/depsgraph.h"
@@ -375,6 +379,11 @@ void deg_evaluate_on_refresh(Depsgraph *graph)
graph->debug.begin_graph_evaluation();
+#ifdef WITH_PYTHON
+ /* Release the GIL so that Python drivers can be evaluated. See T91046. */
+ BPy_BEGIN_ALLOW_THREADS;
+#endif
+
graph->is_evaluating = true;
depsgraph_ensure_view_layer(graph);
/* Set up evaluation state. */
@@ -415,6 +424,10 @@ void deg_evaluate_on_refresh(Depsgraph *graph)
deg_graph_clear_tags(graph);
graph->is_evaluating = false;
+#ifdef WITH_PYTHON
+ BPy_END_ALLOW_THREADS;
+#endif
+
graph->debug.end_graph_evaluation();
}