本文整理汇总了C++中PyEval_ReleaseLock函数的典型用法代码示例。如果您正苦于以下问题:C++ PyEval_ReleaseLock函数的具体用法?C++ PyEval_ReleaseLock怎么用?C++ PyEval_ReleaseLock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyEval_ReleaseLock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: PyEval_AcquireLock
bool KviPythonInterpreter::init()
{
// get the global lock
PyEval_AcquireLock();
// get a reference to the PyInterpreterState
PyInterpreterState * mainInterpreterState = mainThreadState->interp;
// create a thread state object for this thread
m_pThreadState = PyThreadState_New(mainInterpreterState);
// swap in the current thread state
PyThreadState_Swap(m_pThreadState);
// and hook in the kvirc error handling routines
QString szPreCode = QString( \
"import kvirc\n" \
"import sys\n" \
"class kvirc_stderr_grabber:\n" \
"\tdef write(self,s):\n" \
"\t\tkvirc.error(s)\n" \
"sys.stderr=kvirc_stderr_grabber()\n"
);
// evaluate that
PyRun_SimpleString(szPreCode.toUtf8().data());
// swap out our thread state for now
PyThreadState_Swap(NULL);
// free the lock
PyEval_ReleaseLock();
return true;
}
开发者ID:namikaze90,项目名称:KVIrc-old,代码行数:28,代码来源:libkvipythoncore.cpp
示例2: python_init
static int python_init(void)
{
int i;
static char name[] = "radiusd";
if (radiusd_module) return 0;
Py_SetProgramName(name);
Py_Initialize();
PyEval_InitThreads(); /* This also grabs a lock */
if ((radiusd_module = Py_InitModule3("radiusd", radiusd_methods,
"FreeRADIUS Module.")) == NULL)
goto failed;
for (i = 0; radiusd_constants[i].name; i++)
if ((PyModule_AddIntConstant(radiusd_module,
radiusd_constants[i].name,
radiusd_constants[i].value)) < 0)
goto failed;
PyEval_ReleaseLock(); /* Drop lock grabbed by InitThreads */
radlog(L_DBG, "python_init done");
return 0;
failed:
python_error();
Py_XDECREF(radiusd_module);
radiusd_module = NULL;
Py_Finalize();
return -1;
}
开发者ID:darmali,项目名称:freeradius-server,代码行数:33,代码来源:rlm_python.c
示例3: PyEval_AcquireLock
void XBPython::Finalize()
{
if (m_bInitialized)
{
CLog::Log(LOGINFO, "Python, unloading python shared library because no scripts are running anymore");
PyEval_AcquireLock();
PyThreadState_Swap((PyThreadState*)m_mainThreadState);
Py_Finalize();
PyEval_ReleaseLock();
#if !(defined(__APPLE__) || defined(_WIN32))
UnloadExtensionLibs();
#endif
// first free all dlls loaded by python, after that python24.dll (this is done by UnloadPythonDlls
#if !(defined(__APPLE__) || defined(_WIN32))
DllLoaderContainer::UnloadPythonDlls();
#endif
#if defined(_LINUX) && !defined(__APPLE__)
// we can't release it on windows, as this is done in UnloadPythonDlls() for win32 (see above).
// The implementation for linux needs looking at - UnloadPythonDlls() currently only searches for "python24.dll"
// The implementation for osx can never unload the python dylib.
DllLoaderContainer::ReleaseModule(m_pDll);
#endif
m_hModule = NULL;
m_mainThreadState = NULL;
m_bInitialized = false;
}
}
开发者ID:AaronDnz,项目名称:xbmc,代码行数:31,代码来源:XBPython.cpp
示例4: __tr2qs_ctx
bool KviPythonInterpreter::execute(
const QString &szCode,
QStringList &lArgs, //args
QString &szRetVal,
QString &szError,
QStringList &) //lWarnings
{
if(!m_pThreadState)
{
szError = __tr2qs_ctx("Internal error: python interpreter not initialized","python");
return false;
}
int retVal;
g_lError.clear();
// grab the global interpreter lock
PyEval_AcquireLock();
// swap in my thread state
PyThreadState_Swap(m_pThreadState);
QString szVarCode = "aArgs = [";
bool bFirst = true;
foreach(QString szArg,lArgs)
{
if(!bFirst)
szVarCode += ",";
else
bFirst = false;
szVarCode += QString::fromLatin1("\"%1\"").arg(szArg);
}
szVarCode += "]";
PyRun_SimpleString(szVarCode.toUtf8().data());
//clean "cr" from the python code (ticket #1028)
QString szCleanCode = szCode;
szCleanCode.replace(QRegExp("\r\n?"), "\n");
// execute some python code
retVal = PyRun_SimpleString(szCleanCode.toUtf8().data());
szRetVal.setNum(retVal);
if (PyErr_Occurred() || retVal)
{
szError = g_lError;
}
// clear the thread state
PyThreadState_Swap(NULL);
// release our hold on the global interpreter
PyEval_ReleaseLock();
if(retVal)
return false;
return true;
}
开发者ID:namikaze90,项目名称:KVIrc-old,代码行数:60,代码来源:libkvipythoncore.cpp
示例5: PyEval_ReleaseLock
void XBPyThread::OnException()
{
done = true;
m_threadState = NULL;
CLog::Log(LOGERROR,"%s, abnormally terminating python thread", __FUNCTION__);
PyEval_ReleaseLock();
m_pExecuter->setDone(m_id);
}
开发者ID:Avoidnf8,项目名称:xbmc-fork,代码行数:8,代码来源:XBPyThread.cpp
示例6: motor_env_init_v_multi_thread
void
motor_env_init_v_multi_thread()
{
motor_env_init();
if(!PyEval_ThreadsInitialized())
PyEval_InitThreads();
mainThreadState = PyThreadState_Get();
PyEval_ReleaseLock();
}
开发者ID:amogrid,项目名称:redcurrant,代码行数:9,代码来源:c2python.c
示例7: Py_InitializeEx
void ModuleLoader::init()
{
Py_InitializeEx(0);
PyEval_InitThreads(); //note, this implicitly acquires the lock!
g_pymaintstate = PyThreadState_Get();
PyEval_ReleaseLock();
}
开发者ID:BackupTheBerlios,项目名称:bluetool-svn,代码行数:9,代码来源:btool_module_loader.cpp
示例8: assert
/**
* Execute the current script
* We are now in the thread.
*/
void PyApi::ExecuteInThread() const
{
assert(Py_IsInitialized() );
// get the lock so we can change things.
PyEval_AcquireLock();
// make sure that the main thread is the active one.
const auto mainInterpreterState = _mainThreadState->interp;
PyThreadState_Swap(_mainThreadState);
// create a new thread.
const auto myThreadState = PyThreadState_New(mainInterpreterState);
// make sure that the new thread has control
// https://docs.python.org/3/c-api/init.html
PyThreadState_Swap(myThreadState);
// execute it...
{
const auto main_module = PyImport_AddModule("__main__");
const auto main_dict = PyModule_GetDict(main_module);
Py_XINCREF(main_module);
const auto local_dic = PyDict_New();
Py_XINCREF(local_dic);
// we can now run our script
const auto s = _script.c_str();
const auto pyRes = PyRun_String(s, Py_file_input, main_dict, local_dic);
CheckForPythonErrors();
PyDict_Clear(local_dic);
Py_XDECREF(local_dic);
// pending calls must be cleared out
Py_XDECREF(main_module);
}
// swap back to this thread.
PyThreadState_Swap(myThreadState);
// clear anything left behind.
PyThreadState_Clear(myThreadState);
PyThreadState_Swap(nullptr);
// delete my thread.
PyThreadState_Delete(myThreadState);
// give control back to main thread
PyThreadState_Swap(_mainThreadState);
// release the lock one last time.
PyEval_ReleaseLock();
}
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:61,代码来源:pyapi.cpp
示例9: PyThreadState_Swap
void XBPyThread::OnException()
{
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();
CSingleLock lock(m_pExecuter->m_critSection);
m_threadState = NULL;
CLog::Log(LOGERROR,"%s, abnormally terminating python thread", __FUNCTION__);
m_pExecuter->setDone(m_id);
}
开发者ID:AngryByte,项目名称:xbmc,代码行数:10,代码来源:XBPyThread.cpp
示例10: rw_seek_th
static int rw_seek_th(SDL_RWops* context, int offset, int whence)
{
RWHelper* helper = (RWHelper*)context->hidden.unknown.data1;
PyObject* result;
int retval;
PyThreadState* oldstate;
if(!helper->seek || !helper->tell)
return -1;
PyEval_AcquireLock();
oldstate = PyThreadState_Swap(helper->thread);
if(!(offset == 0 && whence == SEEK_CUR)) /*being called only for 'tell'*/
{
result = PyObject_CallFunction(helper->seek, "ii", offset, whence);
if(!result) {
PyErr_Clear();
PyThreadState_Swap(oldstate);
PyEval_ReleaseLock();
return -1;
}
Py_DECREF(result);
}
result = PyObject_CallFunction(helper->tell, NULL);
if(!result) {
PyThreadState_Swap(oldstate);
PyEval_ReleaseLock();
return -1;
}
retval = PyInt_AsLong(result);
Py_DECREF(result);
PyThreadState_Swap(oldstate);
PyEval_ReleaseLock();
return retval;
}
开发者ID:FractalBobz,项目名称:renpy,代码行数:43,代码来源:rwobject.c
示例11: PyThreadState_Swap
PythonThreadState::~PythonThreadState()
{
if(m_thisThreadState)
{
PyThreadState_Swap(m_mainThreadState);
PyThreadState_Clear(m_thisThreadState);
PyThreadState_Delete(m_thisThreadState);
PyEval_ReleaseLock();
}
}
开发者ID:AlistairMills,项目名称:mantid,代码行数:10,代码来源:Threading.cpp
示例12: gil_real_release
void gil_real_release() {
//uwsgi_log("UNLOCK %d\n", uwsgi.mywid);
#if !defined(PYTHREE) && !defined(UWSGI_PYPY)
pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Swap(NULL));
PyEval_ReleaseLock();
#else
pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Get());
PyEval_SaveThread();
#endif
}
开发者ID:20tab,项目名称:uwsgi,代码行数:10,代码来源:gil.c
示例13: do_python_cleanup
/** Cleanup any thread local storage on pthread_exit()
*/
static void do_python_cleanup(void *arg)
{
PyThreadState *my_thread_state = arg;
PyEval_AcquireLock();
PyThreadState_Swap(NULL); /* Not entirely sure this is needed */
PyThreadState_Clear(my_thread_state);
PyThreadState_Delete(my_thread_state);
PyEval_ReleaseLock();
}
开发者ID:padam,项目名称:freeradius-server,代码行数:12,代码来源:rlm_python.c
示例14: PythonEnv_Init
PythonEnv* PythonEnv_Init()
{
PythonEnv* Self = (PythonEnv*) malloc( sizeof( PythonEnv ) );
Py_Initialize();
PyEval_InitThreads();
Self->MainThreadState = PyThreadState_Get();
PyEval_ReleaseLock();
return Self;
}
开发者ID:BackupTheBerlios,项目名称:easyconnect-svn,代码行数:11,代码来源:pythonmodule.c
示例15: BPY_thread_save
/* 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;
}
开发者ID:DarkDefender,项目名称:blender-npr-tess2,代码行数:12,代码来源:bpy_threads.c
示例16: lock
PythonInterpreter::~PythonInterpreter() {
std::lock_guard<std::mutex> lock(globalMutex);
// Acquire the global interpreter lock.
PyEval_RestoreThread(state);
// Destroy the interpreter.
Py_EndInterpreter(state);
// Release the global interpreter lock.
PyEval_ReleaseLock();
}
开发者ID:WPettersson,项目名称:regina,代码行数:12,代码来源:pythoninterpreter.cpp
示例17: PyEval_AcquireLock
void XBPyThread::stop()
{
if (m_threadState)
{
PyEval_AcquireLock();
m_threadState->c_tracefunc = xbTrace;
m_threadState->use_tracing = 1;
PyEval_ReleaseLock();
}
stopping = true;
}
开发者ID:Avoidnf8,项目名称:xbmc-fork,代码行数:12,代码来源:XBPyThread.cpp
示例18: rw_read_th
static int rw_read_th(SDL_RWops* context, void* ptr, int size, int maxnum)
{
RWHelper* helper = (RWHelper*)context->hidden.unknown.data1;
PyObject* result;
int retval;
PyThreadState* oldstate;
if(!helper->read)
return -1;
PyEval_AcquireLock();
oldstate = PyThreadState_Swap(helper->thread);
result = PyObject_CallFunction(helper->read, "i", size * maxnum);
if(!result) {
PyThreadState_Swap(oldstate);
PyEval_ReleaseLock();
return -1;
}
if(!PyString_Check(result))
{
Py_DECREF(result);
PyThreadState_Swap(oldstate);
PyEval_ReleaseLock();
return -1;
}
retval = PyString_GET_SIZE(result);
memcpy(ptr, PyString_AsString(result), retval);
retval /= size;
Py_DECREF(result);
PyThreadState_Swap(oldstate);
PyEval_ReleaseLock();
return retval;
}
开发者ID:FractalBobz,项目名称:renpy,代码行数:40,代码来源:rwobject.c
示例19: PyThreadState_DeleteCurrent
void
PyThreadState_DeleteCurrent()
{
PyThreadState *tstate = _PyThreadState_Current;
if (tstate == NULL)
Py_FatalError(
"PyThreadState_DeleteCurrent: no current tstate");
_PyThreadState_Current = NULL;
tstate_delete_common(tstate);
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
PyThread_delete_key_value(autoTLSkey);
PyEval_ReleaseLock();
}
开发者ID:Av3ng3,项目名称:Lamobo-D1s,代码行数:13,代码来源:pystate.c
示例20: PyThreadState_DeleteCurrent
void
PyThreadState_DeleteCurrent()
{
PyThreadState *tstate = (PyThreadState*)_Py_atomic_load_relaxed(
&_PyThreadState_Current);
if (tstate == NULL)
Py_FatalError(
"PyThreadState_DeleteCurrent: no current tstate");
_Py_atomic_store_relaxed(&_PyThreadState_Current, NULL);
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
PyThread_delete_key_value(autoTLSkey);
tstate_delete_common(tstate);
PyEval_ReleaseLock();
}
开发者ID:Alkalit,项目名称:cpython,代码行数:14,代码来源:pystate.c
注:本文中的PyEval_ReleaseLock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论