#pragma once #include"cstring" #include #include #include #include #include #include "Python.h" #include /*ȫ�ֽ��ͺ��߳���*/ class PyGILThreadLock { public: PyGILThreadLock() { _save = NULL; nStatus = 0; nStatus = PyGILState_Check(); //��⵱ǰ�߳��Ƿ�ӵ��GIL PyGILState_STATE gstate; if (!nStatus) { gstate = PyGILState_Ensure(); //���û��GIL���������ȡGIL nStatus = 1; } _save = PyEval_SaveThread(); PyEval_RestoreThread(_save); } ~PyGILThreadLock() { _save = PyEval_SaveThread(); PyEval_RestoreThread(_save); if (nStatus) { PyGILState_Release(gstate); //�ͷŵ�ǰ�̵߳�GIL } } private: PyGILState_STATE gstate; PyThreadState *_save; int nStatus; };