Blender  V3.3
bpy_threads.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
10 #include <Python.h>
11 
12 #include "../BPY_extern.h"
13 #include "BLI_utildefines.h"
14 
16 {
17  /* Use `_PyThreadState_UncheckedGet()` instead of `PyThreadState_Get()`, to avoid a fatal error
18  * issued when a thread state is NULL (the thread state can be NULL when quitting Blender).
19  *
20  * `PyEval_SaveThread()` will release the GIL, so this thread has to have the GIL to begin with
21  * or badness will ensue. */
22  if (_PyThreadState_UncheckedGet() && PyGILState_Check()) {
23  return (BPy_ThreadStatePtr)PyEval_SaveThread();
24  }
25  return NULL;
26 }
27 
29 {
30  if (tstate) {
31  PyEval_RestoreThread((PyThreadState *)tstate);
32  }
33 }
void * BPy_ThreadStatePtr
Definition: BPY_extern.h:42
BPy_ThreadStatePtr BPY_thread_save(void)
Definition: bpy_threads.c:15
void BPY_thread_restore(BPy_ThreadStatePtr tstate)
Definition: bpy_threads.c:28