• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyThreadState_Get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PyThreadState_Get函数的典型用法代码示例。如果您正苦于以下问题:C++ PyThreadState_Get函数的具体用法?C++ PyThreadState_Get怎么用?C++ PyThreadState_Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PyThreadState_Get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Vignesh2736,项目名称:IncPy,代码行数:19,代码来源:threadmodule.c


示例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();
}
开发者ID:LauraJUK,项目名称:For-The-Vin,代码行数:20,代码来源:psycopgmodule.c


示例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); 

}
开发者ID:joaohf,项目名称:SAFplus-Availability-Scalability-Platform,代码行数:42,代码来源:pyglue.c


示例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;
}
开发者ID:Naddiseo,项目名称:cpython,代码行数:42,代码来源:faulthandler.c


示例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);
}
开发者ID:rajiva,项目名称:SAFplus-Availability-Scalability-Platform,代码行数:42,代码来源:amfpy.c


示例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;
  }
开发者ID:Ayu222,项目名称:android,代码行数:20,代码来源:monitor.cpp


示例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);
}
开发者ID:GuardianRG,项目名称:static-python,代码行数:42,代码来源:callbacks.c


示例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
	}
}
开发者ID:Galland,项目名称:nodebox-opengl,代码行数:41,代码来源:stats.c


示例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");
}}
开发者ID:MatiasNAmendola,项目名称:cleese,代码行数:21,代码来源:pythonrun.c


示例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;
}
开发者ID:DerThorsten,项目名称:pyrtmidi,代码行数:40,代码来源:rtmidimodule.cpp


示例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;
}
开发者ID:pombredanne,项目名称:cpython,代码行数:40,代码来源:faulthandler.c


示例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;
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:40,代码来源:codeobject.c


示例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;
}
开发者ID:CoolJie2001,项目名称:kbengine,代码行数:23,代码来源:script.cpp


示例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;
  }
开发者ID:CaptainRewind,项目名称:xbmc,代码行数:22,代码来源:swig.cpp


示例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;
}
开发者ID:buriy,项目名称:pystemmer,代码行数:22,代码来源:Stemmer.c


示例16: test_repeated_init_and_subinterpreters

static void test_repeated_init_and_subinterpreters(void)
{
    PyThreadState *mainstate, *substate;
#ifdef WITH_THREAD
    PyGILState_STATE gilstate;
#endif
    int i, j;

    for (i=0; i<3; i++) {
        printf("--- Pass %d ---\n", i);
        _testembed_Py_Initialize();
        mainstate = PyThreadState_Get();

#ifdef WITH_THREAD
        PyEval_InitThreads();
        PyEval_ReleaseThread(mainstate);

        gilstate = PyGILState_Ensure();
#endif
        print_subinterp();
        PyThreadState_Swap(NULL);

        for (j=0; j<3; j++) {
            substate = Py_NewInterpreter();
            print_subinterp();
            Py_EndInterpreter(substate);
        }

        PyThreadState_Swap(mainstate);
        print_subinterp();
#ifdef WITH_THREAD
        PyGILState_Release(gilstate);
#endif

        PyEval_RestoreThread(mainstate);
        Py_Finalize();
    }
}
开发者ID:Orav,项目名称:kbengine,代码行数:38,代码来源:_testembed.c


示例17: _PyCrossInterpreterData_Release

void
_PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
{
    if (data->data == NULL && data->obj == NULL) {
        // Nothing to release!
        return;
    }

    // Switch to the original interpreter.
    PyInterpreterState *interp = _PyInterpreterState_LookUpID(data->interp);
    if (interp == NULL) {
        // The intepreter was already destroyed.
        if (data->free != NULL) {
            // XXX Someone leaked some memory...
        }
        return;
    }

    PyThreadState *save_tstate = NULL;
    if (interp != PyThreadState_Get()->interp) {
        // XXX Using the "head" thread isn't strictly correct.
        PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
        // XXX Possible GILState issues?
        save_tstate = PyThreadState_Swap(tstate);
    }

    // "Release" the data and/or the object.
    if (data->free != NULL) {
        data->free(data->data);
    }
    Py_XDECREF(data->obj);

    // Switch back.
    if (save_tstate != NULL) {
        PyThreadState_Swap(save_tstate);
    }
}
开发者ID:arizvisa,项目名称:cpython,代码行数:37,代码来源:pystate.c


示例18: contextvar_set

static int
contextvar_set(PyContextVar *var, PyObject *val)
{
    var->var_cached = NULL;
    PyThreadState *ts = PyThreadState_Get();

    PyContext *ctx = context_get();
    if (ctx == NULL) {
        return -1;
    }

    PyHamtObject *new_vars = _PyHamt_Assoc(
        ctx->ctx_vars, (PyObject *)var, val);
    if (new_vars == NULL) {
        return -1;
    }

    Py_SETREF(ctx->ctx_vars, new_vars);

    var->var_cached = val;  /* borrow */
    var->var_cached_tsid = ts->id;
    var->var_cached_tsver = ts->context_ver;
    return 0;
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:24,代码来源:context.c


示例19: pythoncore_module_init

static bool pythoncore_module_init(KviModule *)
{
#ifdef COMPILE_PYTHON_SUPPORT

	// Initialize the Python interpreter
	Py_Initialize();
	PyEval_InitThreads();

	// save a pointer to the main PyThreadState object
	mainThreadState = PyThreadState_Get();
	// release the lock
	PyEval_ReleaseLock();

	// Initialize the Python module for KVIrc
	python_init();

	g_pInterpreters = new KviPointerHashTable<QString,KviPythonInterpreter>(17,false);
	g_pInterpreters->setAutoDelete(false);
	return true;

#endif // COMPILE_PYTHON_SUPPORT

	return false;
}
开发者ID:kartagis,项目名称:KVIrc,代码行数:24,代码来源:libkvipythoncore.cpp


示例20: _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;

    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;
    PyTraceBack_Here(py_frame);
  bad:
    Py_XDECREF(py_globals);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}
开发者ID:469306621,项目名称:Languages,代码行数:25,代码来源:callbacks.c



注:本文中的PyThreadState_Get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyThread_acquire_lock函数代码示例发布时间:2022-05-30
下一篇:
C++ PyThreadState_GET函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap