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

C++ PyThreadState_GET函数代码示例

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

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



在下文中一共展示了PyThreadState_GET函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: getPythonInterpreterStackTrace

// Python interpreter retrieval routine adapted from
// https://stackoverflow.com/a/8706144
std::string getPythonInterpreterStackTrace() {
  std::stringstream stack_trace;
  AutoGIL gil;
  PyThreadState *tstate = PyThreadState_GET();
  if (NULL != tstate && NULL != tstate->frame) {
    PyFrameObject *frame = tstate->frame;

    while (NULL != frame) {
      int line = PyCode_Addr2Line(frame->f_code, frame->f_lasti);
      std::string filename = THPUtils_unpackString(frame->f_code->co_filename);
      std::string funcname = THPUtils_unpackString(frame->f_code->co_name);
      stack_trace << filename << "(" << line << "): " << funcname << "\n";
      frame = frame->f_back;
    }
  }
  return stack_trace.str();
}
开发者ID:gtgalone,项目名称:pytorch,代码行数:19,代码来源:python_tracer.cpp


示例2: FETCH_ERROR_OCCURRED

// Fetch the current error into object variables.
NUITKA_MAY_BE_UNUSED static void FETCH_ERROR_OCCURRED( PyObject **exception_type, PyObject **exception_value, PyTracebackObject **exception_traceback)
{
    PyThreadState *tstate = PyThreadState_GET();

    *exception_type = tstate->curexc_type;
    *exception_value = tstate->curexc_value;
    *exception_traceback = (PyTracebackObject *)tstate->curexc_traceback;

#if _DEBUG_EXCEPTIONS
    PRINT_STRING("FETCH_ERROR_OCCURRED:\n");
    PRINT_EXCEPTION( tstate->curexc_type,  tstate->curexc_value, tstate->curexc_traceback );
#endif

    tstate->curexc_type = NULL;
    tstate->curexc_value = NULL;
    tstate->curexc_traceback = NULL;
}
开发者ID:justus922,项目名称:Nuitka,代码行数:18,代码来源:exceptions.hpp


示例3: PyThreadState_GET

/* Lookup the error handling callback function registered under the
   name error. As a special case NULL can be passed, in which case
   the error handling callback for strict encoding will be returned. */
PyObject *PyCodec_LookupError(const char *name)
{
    PyObject *handler = NULL;

    PyInterpreterState *interp = PyThreadState_GET()->interp;
    if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
        return NULL;

    if (name==NULL)
        name = "strict";
    handler = PyDict_GetItemString(interp->codec_error_registry, name);
    if (!handler)
        PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name);
    else
        Py_INCREF(handler);
    return handler;
}
开发者ID:Cartmanfku,项目名称:cpython,代码行数:20,代码来源:codecs.c


示例4: CHANNEL_SEND_EXCEPTION_HEAD

static CHANNEL_SEND_EXCEPTION_HEAD(impl_channel_send_exception)
{
	STACKLESS_GETARG();
	PyThreadState *ts = PyThreadState_GET();
	PyObject *bomb, *ret = NULL;

	assert(PyChannel_Check(self));
	if (ts->st.main == NULL)
		return PyChannel_SendException_M(self, klass, args);

	bomb = slp_make_bomb(klass, args, "channel.send_exception");
	if (bomb != NULL) {
		ret = generic_channel_action(self, bomb, 1, stackless);
		Py_DECREF(bomb);
	}
	return ret;
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:17,代码来源:channelobject.c


示例5: toPython

    inline void toPython()
    {
        PyErr_Restore( this->exception_type, this->exception_value, (PyObject *)this->exception_tb );

        assert( this->exception_type );

#ifndef __NUITKA_NO_ASSERT__
        PyThreadState *thread_state = PyThreadState_GET();
#endif

        assert( this->exception_type == thread_state->curexc_type );
        assert( thread_state->curexc_type );

        this->exception_type  = NULL;
        this->exception_value = NULL;
        this->exception_tb    = NULL;
    }
开发者ID:linkerlin,项目名称:Nuitka,代码行数:17,代码来源:exceptions.hpp


示例6: _PyStackless_Init

void
_PyStackless_Init(void)
{
	PyObject *dict;
	PyObject *modules;
	char *name = "stackless";
	PySlpModuleObject *m;

	if (init_slpmoduletype())
		return;

	/* record the thread state for thread support */
	slp_initial_tstate = PyThreadState_GET();

	/* Create the module and add the functions */
	slp_module = PyModule_Create(&stacklessmodule);
	if (slp_module == NULL)
		return; /* errors handled by caller */

	modules = PyImport_GetModuleDict();
	if (PyDict_SetItemString(modules, name, slp_module)) {
		Py_DECREF(slp_module);
		return;
	}
	Py_DECREF(slp_module); /* Yes, it still exists, in modules! */

	if (init_prickelpit()) return;

	dict = PyModule_GetDict(slp_module);

#define INSERT(name, object) \
	if (PyDict_SetItemString(dict, name, (PyObject*)object) < 0) return

	INSERT("slpmodule", PySlpModule_TypePtr);
	INSERT("cframe",    &PyCFrame_Type);
	INSERT("cstack",    &PyCStack_Type);
	INSERT("bomb",	    &PyBomb_Type);
	INSERT("tasklet",   &PyTasklet_Type);
	INSERT("channel",   &PyChannel_Type);
	INSERT("stackless", slp_module);

	m = (PySlpModuleObject *) slp_module;
	slpmodule_set__tasklet__(m, &PyTasklet_Type, NULL);
	slpmodule_set__channel__(m, &PyChannel_Type, NULL);
}
开发者ID:d11,项目名称:rts,代码行数:45,代码来源:stacklessmodule.c


示例7: impl_channel_send_throw

static PyObject *
impl_channel_send_throw(PyChannelObject *self, PyObject *exc, PyObject *val, PyObject *tb)
{
    STACKLESS_GETARG();
    PyThreadState *ts = PyThreadState_GET();
    PyObject *bomb, *ret = NULL;

    assert(PyChannel_Check(self));
    if (ts->st.main == NULL)
        return PyChannel_SendThrow_M(self, exc, val, tb);

    bomb = slp_exc_to_bomb(exc, val, tb);
    if (bomb != NULL) {
        ret = generic_channel_action(self, bomb, 1, stackless);
        Py_DECREF(bomb);
    }
    return ret;
}
开发者ID:Whosemario,项目名称:stackless-python,代码行数:18,代码来源:channelobject.c


示例8: __Pyx_ErrRestore

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
开发者ID:Huskyeder,项目名称:cython,代码行数:18,代码来源:Exceptions.c


示例9: PyThreadState_GET

PyObject *GPU_initPython(void)
{
	PyObject *module;
	PyObject *submodule;
	PyObject *sys_modules = PyThreadState_GET()->interp->modules;

	module = PyInit_gpu();

	PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL));

	/* gpu.offscreen */
	PyModule_AddObject(module, "offscreen", (submodule = BPyInit_gpu_offscreen()));
	PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
	Py_INCREF(submodule);

	PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module);
	return module;
}
开发者ID:UPBGE,项目名称:blender,代码行数:18,代码来源:gpu.c


示例10: PyState_FindModule

PyObject*
PyState_FindModule(struct PyModuleDef* module)
{
    Py_ssize_t index = module->m_base.m_index;
    PyInterpreterState *state = PyThreadState_GET()->interp;
    PyObject *res;
    if (module->m_slots) {
        return NULL;
    }
    if (index == 0)
        return NULL;
    if (state->modules_by_index == NULL)
        return NULL;
    if (index >= PyList_GET_SIZE(state->modules_by_index))
        return NULL;
    res = PyList_GET_ITEM(state->modules_by_index, index);
    return res==Py_None ? NULL : res;
}
开发者ID:Alkalit,项目名称:cpython,代码行数:18,代码来源:pystate.c


示例11: PyErr_SetExcInfo

void
PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback)
{
    PyObject *oldtype, *oldvalue, *oldtraceback;
    PyThreadState *tstate = PyThreadState_GET();

    oldtype = tstate->exc_type;
    oldvalue = tstate->exc_value;
    oldtraceback = tstate->exc_traceback;

    tstate->exc_type = p_type;
    tstate->exc_value = p_value;
    tstate->exc_traceback = p_traceback;

    Py_XDECREF(oldtype);
    Py_XDECREF(oldvalue);
    Py_XDECREF(oldtraceback);
}
开发者ID:cpcloud,项目名称:cpython,代码行数:18,代码来源:errors.c


示例12: PyCodec_Register

int PyCodec_Register(PyObject *search_function)
{
    PyInterpreterState *interp = PyThreadState_GET()->interp;
    if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
        goto onError;
    if (search_function == NULL) {
        PyErr_BadArgument();
        goto onError;
    }
    if (!PyCallable_Check(search_function)) {
        PyErr_SetString(PyExc_TypeError, "argument must be callable");
        goto onError;
    }
    return PyList_Append(interp->codec_search_path, search_function);

 onError:
    return -1;
}
开发者ID:0xcc,项目名称:python-read,代码行数:18,代码来源:codecs.c


示例13: _PyState_AddModule

int
_PyState_AddModule(PyObject* module, struct PyModuleDef* def)
{
    PyInterpreterState *state = PyThreadState_GET()->interp;
    if (!def)
        return -1;
    if (!state->modules_by_index) {
        state->modules_by_index = PyList_New(0);
        if (!state->modules_by_index)
            return -1;
    }
    while(PyList_GET_SIZE(state->modules_by_index) <= def->m_base.m_index)
        if (PyList_Append(state->modules_by_index, Py_None) < 0)
            return -1;
    Py_INCREF(module);
    return PyList_SetItem(state->modules_by_index,
                          def->m_base.m_index, module);
}
开发者ID:packages,项目名称:python,代码行数:18,代码来源:pystate.c


示例14: DEBUG

//=============================================================================
// METHOD    : SPELLwsWarmStartImpl::fixState()
//=============================================================================
PyFrameObject* SPELLwsWarmStartImpl::fixState()
{
	DEBUG("[WS] Fixing state ==============================================");

	// Synchronize so that nothing can be done while saving
	SPELLmonitor m(m_lock);

	// Get the head interpreter state
	PyInterpreterState* istate = PyInterpreterState_Head();

	// Get the current thread state
	PyThreadState* oldState = PyThreadState_GET();
	DEBUG("[WS] Old state: " + PSTR(oldState));
	DEBUG("[WS] Interpreter head: " + PSTR(istate->tstate_head));
	DEBUG("[WS] Interpreter next: " + PSTR(istate->next));
	DEBUG("[WS] State recursion depth: " + ISTR(oldState->recursion_depth));
	DEBUG("[WS] State next: " + PSTR(oldState->next));

	// Create a fresh thread state
	PyThreadState* newState = PyThreadState_New(istate);
	istate->tstate_head = newState;

	newState->recursion_depth = oldState->recursion_depth;
	newState->tracing = oldState->tracing;
	newState->use_tracing = oldState->use_tracing;
	newState->tick_counter = oldState->tick_counter;
	newState->gilstate_counter = oldState->gilstate_counter;
	newState->dict = PyDict_Copy(oldState->dict);

	FrameList::iterator it;
	unsigned int frameCount = m_frames.size();
	DEBUG("[WS] Total frames to fix " + ISTR(frameCount));
	m_topFrame = NULL;
	for( unsigned int index = 0; index < frameCount; index++)
	{
		bool isHead = (index == (frameCount-1));
		DEBUG("[WS] Fix state on frame index " + ISTR(index) + " frame=" + PYCREPR(m_frames[index]));
		m_topFrame = m_frames[index];
		m_topFrame->fixState(newState, isHead);
	}
	DEBUG("[WS] State fixed ===============================================");
	PyErr_Clear();
	return m_topFrame->getFrameObject();
}
开发者ID:unnch,项目名称:spell-sat,代码行数:47,代码来源:SPELLwsWarmStartImpl.C


示例15: __Pyx_GetException

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
    if (unlikely(tstate->curexc_type))
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
        goto bad;
    #endif
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
    Py_INCREF(local_type);
    Py_INCREF(local_value);
    Py_INCREF(local_tb);
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    /* Make sure tstate is in a consistent state when we XDECREF
       these objects (XDECREF may run arbitrary code). */
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}
开发者ID:dynamicgl,项目名称:CythonCTypesBackend,代码行数:44,代码来源:Exceptions.c


示例16: signal_handler

void signal_handler(int sig_num) {
    printf("Trapped signal %d in C++ layer, exiting\n", sig_num);
 	//PyErr_SetString(PyExc_ValueError,"Trapped signal in C++ layer, exiting");
    printf("\n");
    PyThreadState *tstate = PyThreadState_GET();
    if (NULL != tstate && NULL != tstate->frame) {
        PyFrameObject *frame = tstate->frame;

        printf("Python stack trace:\n");
        while (NULL != frame) {
            int line = frame->f_lineno;
            const char *filename = PyString_AsString(frame->f_code->co_filename);
            const char *funcname = PyString_AsString(frame->f_code->co_name);
            printf("    %s(%d): %s\n", filename, line, funcname);
            frame = frame->f_back;
        }
    }
    exit(0);
}
开发者ID:autumnm1981,项目名称:Halide,代码行数:19,代码来源:py_util.cpp


示例17: DROP_ERROR_OCCURRED

// Clear error, which is not likely set. This is about bugs from CPython,
// use CLEAR_ERROR_OCCURRED is not sure.
NUITKA_MAY_BE_UNUSED static inline void DROP_ERROR_OCCURRED( void )
{
    PyThreadState *tstate = PyThreadState_GET();

    if (unlikely( tstate->curexc_type != NULL ))
    {
        PyObject *old_type  = tstate->curexc_type;
        PyObject *old_value = tstate->curexc_value;
        PyObject *old_tb    = tstate->curexc_traceback;

        tstate->curexc_type = NULL;
        tstate->curexc_value = NULL;
        tstate->curexc_traceback = NULL;

        Py_DECREF( old_type );
        Py_XDECREF( old_value );
        Py_XDECREF( old_tb );
    }
}
开发者ID:justus922,项目名称:Nuitka,代码行数:21,代码来源:exceptions.hpp


示例18: TASKLET_RAISE_EXCEPTION_HEAD

static TASKLET_RAISE_EXCEPTION_HEAD(impl_tasklet_raise_exception)
{
    STACKLESS_GETARG();
    PyThreadState *ts = PyThreadState_GET();
    PyObject *bomb;

    if (ts->st.main == NULL)
        return PyTasklet_RaiseException_M(self, klass, args);
    bomb = slp_make_bomb(klass, args, "tasklet.raise_exception");
    if (bomb == NULL)
        return NULL;
    TASKLET_SETVAL_OWN(self, bomb);
    /* if the tasklet is dead, do not run it (no frame) but explode */
    if (slp_get_frame(self) == NULL) {
        TASKLET_CLAIMVAL(self, &bomb);
        return slp_bomb_explode(bomb);
    }
    return slp_schedule_task(ts->st.current, self, stackless, 0);
}
开发者ID:newerthcom,项目名称:savagerebirth,代码行数:19,代码来源:taskletobject.c


示例19: PyInit_mathutils

PyMODINIT_FUNC PyInit_mathutils(void)
{
	PyObject *submodule;
	PyObject *item;
	PyObject *sys_modules= PyThreadState_GET()->interp->modules;

	if (PyType_Ready(&vector_Type) < 0)
		return NULL;
	if (PyType_Ready(&matrix_Type) < 0)
		return NULL;	
	if (PyType_Ready(&euler_Type) < 0)
		return NULL;
	if (PyType_Ready(&quaternion_Type) < 0)
		return NULL;
	if (PyType_Ready(&color_Type) < 0)
		return NULL;

	submodule = PyModule_Create(&M_Mathutils_module_def);
	
	/* each type has its own new() function */
	PyModule_AddObject(submodule, "Vector",		(PyObject *)&vector_Type);
	PyModule_AddObject(submodule, "Matrix",		(PyObject *)&matrix_Type);
	PyModule_AddObject(submodule, "Euler",		(PyObject *)&euler_Type);
	PyModule_AddObject(submodule, "Quaternion",	(PyObject *)&quaternion_Type);
	PyModule_AddObject(submodule, "Color",		(PyObject *)&color_Type);
	
	/* submodule */
	PyModule_AddObject(submodule, "geometry",		(item=PyInit_mathutils_geometry()));
	/* XXX, python doesnt do imports with this usefully yet
	 * 'from mathutils.geometry import PolyFill'
	 * ...fails without this. */
	PyDict_SetItemString(sys_modules, "mathutils.geometry", item);
	Py_INCREF(item);

	/* Noise submodule */
	PyModule_AddObject(submodule, "noise",		(item=PyInit_mathutils_noise()));
	PyDict_SetItemString(sys_modules, "mathutils.noise", item);
	Py_INCREF(item);

	mathutils_matrix_vector_cb_index= Mathutils_RegisterCallback(&mathutils_matrix_vector_cb);

	return submodule;
}
开发者ID:mik0001,项目名称:Blender,代码行数:43,代码来源:mathutils.c


示例20: CHAIN_EXCEPTION

static void CHAIN_EXCEPTION( PyObject *exception_type, PyObject *exception_value )
{
    // Implicit chain of exception already existing.
    PyThreadState *thread_state = PyThreadState_GET();

    // Normalize existing exception first. TODO: Will normally be done already.
    NORMALIZE_EXCEPTION(
        &thread_state->exc_type,
        &thread_state->exc_value,
        (PyTracebackObject **)&thread_state->exc_traceback
    );

    PyObject *old_exc_value = thread_state->exc_value;

    if ( old_exc_value != NULL && old_exc_value != Py_None && old_exc_value != exception_value )
    {
        PyObject *current = old_exc_value;
        while( true )
        {
            PyObject *context = PyException_GetContext( current );
            if (!context) break;

            CHECK_OBJECT( context );
            Py_DECREF( context );
            CHECK_OBJECT( context );

            if ( context == exception_value )
            {
                PyException_SetContext( current, NULL );
                break;
            }

            current = context;
        }

        CHECK_OBJECT( old_exc_value );
        Py_INCREF( old_exc_value );
        PyException_SetContext( exception_value, old_exc_value );

        CHECK_OBJECT( thread_state->exc_traceback );
        PyException_SetTraceback( old_exc_value, thread_state->exc_traceback );
    }
}
开发者ID:justus922,项目名称:Nuitka,代码行数:43,代码来源:raising.hpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PyThreadState_Get函数代码示例发布时间:2022-05-30
下一篇:
C++ PyThreadState_Clear函数代码示例发布时间: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