This commit is contained in:
wangjiyu 2025-04-15 21:59:17 +08:00
parent 4d439101ca
commit 0673469b29
1 changed files with 4 additions and 0 deletions

View File

@ -1,14 +1,18 @@
#include <Python.h> #include <Python.h>
#include <stdio.h>
#include <iostream>
struct PyLockGIL struct PyLockGIL
{ {
PyLockGIL(): gstate(PyGILState_Ensure()) PyLockGIL(): gstate(PyGILState_Ensure())
{ {
std::cout << "construct GIL" << std::endl;
} }
~PyLockGIL() ~PyLockGIL()
{ {
PyGILState_Release(gstate); PyGILState_Release(gstate);
std::cout << "destruct GIL" << std::endl;
} }
PyLockGIL(const PyLockGIL&) = delete; PyLockGIL(const PyLockGIL&) = delete;