diff options
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 7a3d56dc56d..9fbad956d6d 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -408,6 +408,31 @@ void BPY_python_reset(bContext *C) BPY_modules_load_user(C); } +/* wrapper functions related to global interpreter lock. these functions + * are slightly different from the original Python API, don't throw + * SIGABRT even if the thread state is NULL. */ + +/* analogue of PyEval_SaveThread() */ +BPy_ThreadStatePtr BPY_thread_save(void) +{ + PyThreadState *tstate = PyThreadState_Swap(NULL); + /* note: tstate can be NULL when quitting Blender */ + + if (tstate && PyEval_ThreadsInitialized()) { + PyEval_ReleaseLock(); + } + + return (BPy_ThreadStatePtr)tstate; +} + +/* analogue of PyEval_RestoreThread() */ +void BPY_thread_restore(BPy_ThreadStatePtr tstate) +{ + if (tstate) { + PyEval_RestoreThread((PyThreadState *)tstate); + } +} + static void python_script_error_jump_text(struct Text *text) { int lineno; |