本文整理汇总了C++中PyThreadState_Get函数的典型用法代码示例。如果您正苦于以下问题:C++ PyThreadState_Get函数的具体用法?C++ PyThreadState_Get怎么用?C++ PyThreadState_Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyThreadState_Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: local_dealloc
static void
local_dealloc(localobject *self)
{
PyThreadState *tstate;
if (self->key
&& (tstate = PyThreadState_Get())
&& tstate->interp) {
for(tstate = PyInterpreterState_ThreadHead(tstate->interp);
tstate;
tstate = PyThreadState_Next(tstate))
if (tstate->dict &&
PyDict_GetItem(tstate->dict, self->key))
PyDict_DelItem(tstate->dict, self->key);
}
Py_XDECREF(self->key);
local_clear(self);
Py_TYPE(self)->tp_free((PyObject*)self);
}
示例2: psyco_is_main_interp
/* Return nonzero if the current one is the main interpreter */
static int
psyco_is_main_interp(void)
{
static PyInterpreterState *main_interp = NULL; /* Cached reference */
PyInterpreterState *interp;
if (main_interp) {
return (main_interp == PyThreadState_Get()->interp);
}
/* No cached value: cache the proper value and try again. */
interp = PyInterpreterState_Head();
while (interp->next)
interp = interp->next;
main_interp = interp;
assert (main_interp);
return psyco_is_main_interp();
}
示例3: clPyGlueInit
void clPyGlueInit(char* appModule,void (*init_extensions[])(void),int argc, char**argv)
{
char buf[1024];
ClRcT rc;
Py_Initialize();
PySys_SetArgv(argc, argv);
PyEval_InitThreads();
if (init_extensions)
{
int i = 0;
for(i=0; init_extensions[i]!=NULL; i++) (*init_extensions[i])();
}
thrdState = PyThreadState_Get();
rc = clOsalMutexInit(&pyMutex);
CL_ASSERT(rc==CL_OK);
rc = clOsalCondInit(&event);
CL_ASSERT(rc==CL_OK);
rc = clOsalMutexLock(&pyMutex);
CL_ASSERT(rc==CL_OK);
PyThreadState_Swap(thrdState);
PyRun_SimpleString("import os, os.path, sys\n");
snprintf(buf,1024,"sys.path.append(os.path.realpath('%s'))\n",CL_APP_BINDIR);
clprintf(CL_LOG_SEV_INFO, buf);
PyRun_SimpleString(buf);
//PyRun_SimpleString("sys.path.append(os.path.realpath('../../bin'))\n");
snprintf(buf,1024,"from %s import *\n",appModule);
clprintf(CL_LOG_SEV_INFO, buf);
PyRun_SimpleString(buf);
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();
rc=clOsalMutexUnlock(&pyMutex);
CL_ASSERT(rc==CL_OK);
}
示例4: faulthandler_user
static void
faulthandler_user(int signum)
{
user_signal_t *user;
PyThreadState *tstate;
int save_errno = errno;
user = &user_signals[signum];
if (!user->enabled)
return;
#ifdef WITH_THREAD
/* PyThreadState_Get() doesn't give the state of the current thread if
the thread doesn't hold the GIL. Read the thread local storage (TLS)
instead: call PyGILState_GetThisThreadState(). */
tstate = PyGILState_GetThisThreadState();
#else
tstate = PyThreadState_Get();
#endif
if (user->all_threads)
_Py_DumpTracebackThreads(user->fd, user->interp, tstate);
else {
if (tstate == NULL)
return;
_Py_DumpTraceback(user->fd, tstate);
}
#ifdef HAVE_SIGACTION
if (user->chain) {
(void)sigaction(signum, &user->previous, NULL);
/* call the previous signal handler */
raise(signum);
(void)faulthandler_register(signum, user->chain, NULL);
}
#else
if (user->chain) {
/* call the previous signal handler */
user->previous(signum);
}
#endif
errno = save_errno;
}
示例5: clRunPython
static void clRunPython(char* cmd)
{
#define BSZ 2048
char pyBuf[BSZ];
clprintf (CL_LOG_SEV_INFO, "clRunPython called with [%s]", cmd);
//clOsalMutexLock(&pyMutex);
thrdState = PyThreadState_Get();
#if 0
if (quit)
{
clprintf(CL_LOG_SEV_INFO,"Python has quit, so not running: %s",cmd);
//clOsalMutexUnlock(&pyMutex);
return;
}
#endif
#if 0
PyEval_AcquireLock();
PyThreadState_Swap(thrdState);
#endif
snprintf(pyBuf,BSZ,"clCmdFromAsp(\"\"\"%s\"\"\")\n",cmd);
clprintf (CL_LOG_SEV_INFO, "clRunPython requesting python lock [%s]", cmd);
PyEval_AcquireThread(thrdState);
clprintf(CL_LOG_SEV_INFO,"Stage 1. Passing to Python layer: %s",pyBuf);
int ret = PyRun_SimpleString(pyBuf);
clprintf (CL_LOG_SEV_INFO, "clRunPython requesting release of python lock [%s]", cmd);
PyEval_ReleaseThread(thrdState);
if (ret != 0) clprintf(CL_LOG_SEV_ERROR,"Ran: %s. There was an error.",pyBuf);
#if 0
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();
#endif
//clprintf (CL_LOG_SEV_INFO, "clRunPython unlocking mutex [%s]", cmd);
//clOsalMutexUnlock(&pyMutex);
//clprintf (CL_LOG_SEV_INFO, "clRunPython unlocked mutex [%s]", cmd);
}
示例6: Monitor_New
PyObject* Monitor_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
Monitor *self;
self = (Monitor*)type->tp_alloc(type, 0);
if (!self) return NULL;
std::string addonId;
if (!PyXBMCGetAddonId(addonId) || addonId.empty())
{
PyErr_SetString((PyObject*)self, "Unable to identify addon");
return NULL;
}
CPyThreadState pyState;
self->pMonitor = new CPythonMonitor();
pyState.Restore();
self->pMonitor->Id = addonId;
self->pMonitor->SetCallback(PyThreadState_Get(), (PyObject*)self);
return (PyObject*)self;
}
示例7: _ctypes_add_traceback
/* after code that pyrex generates */
void _ctypes_add_traceback(char *funcname, char *filename, int lineno)
{
PyObject *py_globals = 0;
PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0;
PyObject *exception, *value, *tb;
/* (Save and) Clear the current exception. Python functions must not be
called with an exception set. Calling Python functions happens when
the codec of the filesystem encoding is implemented in pure Python. */
PyErr_Fetch(&exception, &value, &tb);
py_globals = PyDict_New();
if (!py_globals)
goto bad;
py_code = PyCode_NewEmpty(filename, funcname, lineno);
if (!py_code)
goto bad;
py_frame = PyFrame_New(
PyThreadState_Get(), /*PyThreadState *tstate,*/
py_code, /*PyCodeObject *code,*/
py_globals, /*PyObject *globals,*/
0 /*PyObject *locals*/
);
if (!py_frame)
goto bad;
py_frame->f_lineno = lineno;
PyErr_Restore(exception, value, tb);
PyTraceBack_Here(py_frame);
Py_DECREF(py_globals);
Py_DECREF(py_code);
Py_DECREF(py_frame);
return;
bad:
Py_XDECREF(py_globals);
Py_XDECREF(py_code);
Py_XDECREF(py_frame);
}
示例8: psyco_stats_reset
DEFINEFN
void psyco_stats_reset(void)
{
/* reset all stats */
int i = 0;
PyObject *key, *value, *d;
stats_printf(("stats: reset\n"));
/* reset the charge of all PyCodeStats, keep only the used ones */
RECLIMIT_SAFE_ENTER();
d = PyDict_New();
if (d == NULL)
OUT_OF_MEMORY();
while (PyDict_Next(codestats_dict, &i, &key, &value)) {
PyCodeStats* cs = (PyCodeStats*) key;
if (cs->st_mergepoints) {
/* clear the charge and keep alive */
cs->st_charge = 0.0f;
if (PyDict_SetItem(d, key, value))
OUT_OF_MEMORY();
}
}
RECLIMIT_SAFE_LEAVE();
Py_DECREF(codestats_dict);
codestats_dict = d;
charge_total = 0.0;
charge_prelimit = 0.0f;
/* reset the time measure in all threads */
{
#if MEASURE_ALL_THREADS
PyInterpreterState* istate = PyThreadState_Get()->interp;
PyThreadState* tstate;
for (tstate=istate->tstate_head; tstate; tstate=tstate->next) {
(void) get_measure(tstate);
}
#else
(void) get_measure(NULL);
#endif
}
}
示例9: Py_Finalize
void
Py_Finalize(void)
{
LOG("> Py_Finalize\n"); {
PyInterpreterState *interp;
PyThreadState *tstate;
initialized = 0;
tstate = PyThreadState_Get();
interp = tstate->interp;
PyInterpreterState_Clear(interp);
PyThreadState_Swap(NULL);
PyInterpreterState_Delete(interp);
PyFrame_Fini();
PyInt_Fini();
LOG("< Py_Finalize\n");
}}
示例10: MidiIn_openPort
static PyObject *
MidiIn_openPort(MidiIn *self, PyObject *args)
{
int port;
char *name = NULL;
if(!PyArg_ParseTuple(args, "i|s", &port, &name))
return NULL;
if (name == NULL)
{
try
{
self->rtmidi->openPort(port);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
else
{
try
{
self->rtmidi->openPort(port,name);
}
catch(RtError &error)
{
PyErr_SetString(RtMidiError, error.getMessageString());
return NULL;
}
}
self->rtmidi->setCallback(MidiIn_callback, self);
self->calling_thread_id = PyThreadState_Get()->thread_id;
Py_RETURN_NONE;
}
示例11: faulthandler_dump_traceback_py
static PyObject*
faulthandler_dump_traceback_py(PyObject *self,
PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"file", "all_threads", NULL};
PyObject *file = NULL;
int all_threads = 0;
PyThreadState *tstate;
const char *errmsg;
int fd;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|Oi:dump_traceback", kwlist,
&file, &all_threads))
return NULL;
file = faulthandler_get_fileno(file, &fd);
if (file == NULL)
return NULL;
/* The caller holds the GIL and so PyThreadState_Get() can be used */
tstate = PyThreadState_Get();
if (tstate == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"unable to get the current thread state");
return NULL;
}
if (all_threads) {
errmsg = _Py_DumpTracebackThreads(fd, tstate->interp, tstate);
if (errmsg != NULL) {
PyErr_SetString(PyExc_RuntimeError, errmsg);
return NULL;
}
}
else {
_Py_DumpTraceback(fd, tstate);
}
Py_RETURN_NONE;
}
示例12: _PyCode_SetExtra
int
_PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
{
PyInterpreterState *interp = PyThreadState_Get()->interp;
if (!PyCode_Check(code) || index < 0 ||
index >= interp->co_extra_user_count) {
PyErr_BadInternalCall();
return -1;
}
PyCodeObject *o = (PyCodeObject*) code;
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra *) o->co_extra;
if (co_extra == NULL || co_extra->ce_size <= index) {
Py_ssize_t i = (co_extra == NULL ? 0 : co_extra->ce_size);
co_extra = PyMem_Realloc(
co_extra,
sizeof(_PyCodeObjectExtra) +
(interp->co_extra_user_count-1) * sizeof(void*));
if (co_extra == NULL) {
return -1;
}
for (; i < interp->co_extra_user_count; i++) {
co_extra->ce_extras[i] = NULL;
}
co_extra->ce_size = interp->co_extra_user_count;
o->co_extra = co_extra;
}
if (co_extra->ce_extras[index] != NULL) {
freefunc free = interp->co_extra_freefuncs[index];
if (free != NULL) {
free(co_extra->ce_extras[index]);
}
}
co_extra->ce_extras[index] = extra;
return 0;
}
示例13: PyThreadState_Get
//-------------------------------------------------------------------------------------
PyThreadState* Script::createInterpreter()
{
PyThreadState* pCurInterpreter = PyThreadState_Get();
PyObject * pCurPath = PySys_GetObject( "path" );
PyThreadState* pNewInterpreter = Py_NewInterpreter();
if (pNewInterpreter)
{
PySys_SetObject( "path", pCurPath );
#ifndef KBE_SINGLE_THREADED
PyDict_Merge( PySys_GetObject( "modules" ), s_pOurInitTimeModules, 0 );
#endif
PyThreadState* pSwapped = PyThreadState_Swap( pCurInterpreter );
if( pSwapped != pNewInterpreter )
{
KBE_EXIT( "error creating new python interpreter" );
}
}
return pNewInterpreter;
}
示例14: handleInterpRegistrationForClean
static bool handleInterpRegistrationForClean(XBMCAddon::AddonClass* c)
{
XBMC_TRACE;
if(c){
XBMCAddon::AddonClass::Ref<XBMCAddon::Python::PythonLanguageHook> lh =
XBMCAddon::AddonClass::Ref<XBMCAddon::AddonClass>(c->GetLanguageHook());
if (lh.isNotNull())
{
lh->UnregisterAddonClassInstance(c);
return true;
}
else
{
PyThreadState* state = PyThreadState_Get();
lh = XBMCAddon::Python::PythonLanguageHook::GetIfExists(state->interp);
if (lh.isNotNull()) lh->UnregisterAddonClassInstance(c);
return true;
}
}
return false;
}
示例15: __Pyx_GetException
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
PyThreadState *tstate = PyThreadState_Get();
PyErr_Fetch(type, value, tb);
PyErr_NormalizeException(type, value, tb);
if (PyErr_Occurred())
goto bad;
Py_INCREF(*type);
Py_INCREF(*value);
Py_INCREF(*tb);
Py_XDECREF(tstate->exc_type);
Py_XDECREF(tstate->exc_value);
Py_XDECREF(tstate->exc_traceback);
tstate->exc_type = *type;
tstate->exc_value = *value;
tstate->exc_traceback = *tb;
return 0;
bad:
Py_XDECREF(*type);
Py_XDECREF(*value);
Py_XDECREF(*tb);
return -1;
}