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

C++ PyThreadState_Clear函数代码示例

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

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



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

示例1: PyInterpreterState_Clear

void
PyInterpreterState_Clear(PyInterpreterState *interp)
{
    PyThreadState *p;
    HEAD_LOCK();
    for (p = interp->tstate_head; p != NULL; p = p->next)
        PyThreadState_Clear(p);
    HEAD_UNLOCK();
    _PyCoreConfig_Clear(&interp->core_config);
    _PyMainInterpreterConfig_Clear(&interp->config);
    Py_CLEAR(interp->codec_search_path);
    Py_CLEAR(interp->codec_search_cache);
    Py_CLEAR(interp->codec_error_registry);
    Py_CLEAR(interp->modules);
    Py_CLEAR(interp->modules_by_index);
    Py_CLEAR(interp->sysdict);
    Py_CLEAR(interp->builtins);
    Py_CLEAR(interp->builtins_copy);
    Py_CLEAR(interp->importlib);
    Py_CLEAR(interp->import_func);
#ifdef HAVE_FORK
    Py_CLEAR(interp->before_forkers);
    Py_CLEAR(interp->after_forkers_parent);
    Py_CLEAR(interp->after_forkers_child);
#endif
}
开发者ID:arizvisa,项目名称:cpython,代码行数:26,代码来源:pystate.c


示例2: rw_close_th

static int rw_close_th(SDL_RWops* context)
{
	RWHelper* helper = (RWHelper*)context->hidden.unknown.data1;
	PyObject* result;
	int retval = 0;
        PyThreadState* oldstate;

        PyEval_AcquireLock();
        oldstate = PyThreadState_Swap(helper->thread);

	if(helper->close)
	{
		result = PyObject_CallFunction(helper->close, NULL);
		if(result)
			retval = -1;
		Py_XDECREF(result);
	}

        PyThreadState_Swap(oldstate);
        PyThreadState_Clear(helper->thread);
        PyThreadState_Delete(helper->thread);

	Py_XDECREF(helper->seek);
	Py_XDECREF(helper->tell);
	Py_XDECREF(helper->write);
	Py_XDECREF(helper->read);
	Py_XDECREF(helper->close);
	PyMem_Del(helper);

        PyEval_ReleaseLock();

	SDL_FreeRW(context);
	return retval;
}
开发者ID:FractalBobz,项目名称:renpy,代码行数:34,代码来源:rwobject.c


示例3: z_policy_thread_destroy

/**
 * z_policy_thread_destroy:
 * @self: this
 *
 * Destructor of ZPolicyThread.
 * The embedded Python thread context (self->thread) will be cleared and 
 * deleted also, and if this thread was the last one running in the
 * interpreter instance, that will be stopped, too.
 */
void
z_policy_thread_destroy(ZPolicyThread *self)
{
  /* acquires the interpreter lock */

  if (self->policy->main_thread != self)
    {
      /* we are one of the secondary threads */
      z_python_lock();
      PyThreadState_Swap(self->thread);
      PyThreadState_Clear(self->thread);
      PyThreadState_Swap(NULL);
      PyThreadState_Delete(self->thread);
      z_python_unlock();
      z_policy_unref(self->policy);
    }
  else
    {
      /* we must be freed at last, when the policy is being destroyed */
      g_assert(self->policy->ref_cnt == 1);
      /* we are the main thread, destroy the interpreter */
      z_policy_purge(self->policy);
      PyEval_AcquireThread(self->thread);
      Py_EndInterpreter(self->thread);
      z_python_unlock();
    }
  g_mutex_free(self->startable_lock);
  g_cond_free(self->startable_signal);
  g_free(self);
}
开发者ID:kkovaacs,项目名称:zorp,代码行数:39,代码来源:pypolicy.c


示例4: _PyThreadState_DeleteExcept

/*
 * Delete all thread states except the one passed as argument.
 * Note that, if there is a current thread state, it *must* be the one
 * passed as argument.  Also, this won't touch any other interpreters
 * than the current one, since we don't know which thread state should
 * be kept in those other interpreteres.
 */
void
_PyThreadState_DeleteExcept(PyThreadState *tstate)
{
    PyInterpreterState *interp = tstate->interp;
    PyThreadState *p, *next, *garbage;
    HEAD_LOCK();
    /* Remove all thread states, except tstate, from the linked list of
       thread states.  This will allow calling PyThreadState_Clear()
       without holding the lock. */
    garbage = interp->tstate_head;
    if (garbage == tstate)
        garbage = tstate->next;
    if (tstate->prev)
        tstate->prev->next = tstate->next;
    if (tstate->next)
        tstate->next->prev = tstate->prev;
    tstate->prev = tstate->next = NULL;
    interp->tstate_head = tstate;
    HEAD_UNLOCK();
    /* Clear and deallocate all stale thread states.  Even if this
       executes Python code, we should be safe since it executes
       in the current thread, not one of the stale threads. */
    for (p = garbage; p; p = next) {
        next = p->next;
        PyThreadState_Clear(p);
        PyMem_RawFree(p);
    }
}
开发者ID:Alkalit,项目名称:cpython,代码行数:35,代码来源:pystate.c


示例5: KBE_EXIT

//-------------------------------------------------------------------------------------
void Script::finiThread( bool plusOwnInterpreter )
{
	if( s_defaultContext != PyThreadState_Get() )
	{
		KBE_EXIT( "trying to finalise script thread when not in default context" );
	}

	if (plusOwnInterpreter)
	{
		{
			PyInterpreterState_Clear( s_defaultContext->interp );
			PyThreadState_Swap( NULL );
			PyInterpreterState_Delete( s_defaultContext->interp );
		}

		PyEval_ReleaseLock();
	}
	else
	{
		PyThreadState_Clear( s_defaultContext );
		PyThreadState_DeleteCurrent();								// releases GIL
	}

	s_defaultContext = NULL;
}
开发者ID:CoolJie2001,项目名称:kbengine,代码行数:26,代码来源:script.cpp


示例6: t_bootstrap

static void
t_bootstrap(void *boot_raw)
{
	struct bootstate *boot = (struct bootstate *) boot_raw;
	PyThreadState *tstate;
	PyObject *res;

	tstate = PyThreadState_New(boot->interp);
	PyEval_AcquireThread(tstate);
	res = PyEval_CallObjectWithKeywords(
		boot->func, boot->args, boot->keyw);
	Py_DECREF(boot->func);
	Py_DECREF(boot->args);
	Py_XDECREF(boot->keyw);
	PyMem_DEL(boot_raw);
	if (res == NULL) {
		if (PyErr_ExceptionMatches(PyExc_SystemExit))
			PyErr_Clear();
		else {
			PySys_WriteStderr("Unhandled exception in thread:\n");
			PyErr_PrintEx(0);
		}
	}
	else
		Py_DECREF(res);
	PyThreadState_Clear(tstate);
	PyThreadState_DeleteCurrent();
	PyThread_exit_thread();
}
开发者ID:weimingtom,项目名称:SimpleScriptSystem,代码行数:29,代码来源:threadmodule.c


示例7: 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


示例8: Py_NewInterpreter

PyThreadState *
Py_NewInterpreter(void)
{
	PyInterpreterState *interp;
	PyThreadState *tstate, *save_tstate;
	PyObject *bimod, *sysmod;

	if (!initialized)
		Py_FatalError("Py_NewInterpreter: call Py_Initialize first");

	interp = PyInterpreterState_New();
	if (interp == NULL)
		return NULL;

	tstate = PyThreadState_New(interp);
	if (tstate == NULL) {
		PyInterpreterState_Delete(interp);
		return NULL;
	}

	save_tstate = PyThreadState_Swap(tstate);

	/* XXX The following is lax in error checking */

	interp->modules = PyDict_New();

	bimod = _PyImport_FindExtension("__builtin__", "__builtin__");
	if (bimod != NULL) {
		interp->builtins = PyModule_GetDict(bimod);
		Py_INCREF(interp->builtins);
	}
	sysmod = _PyImport_FindExtension("sys", "sys");
	if (bimod != NULL && sysmod != NULL) {
		interp->sysdict = PyModule_GetDict(sysmod);
		Py_INCREF(interp->sysdict);
		PySys_SetPath(Py_GetPath());
		PyDict_SetItemString(interp->sysdict, "modules",
				     interp->modules);
		initmain();
		if (!Py_NoSiteFlag)
			initsite();
	}

	if (!PyErr_Occurred())
		return tstate;

	/* Oops, it didn't work.  Undo it all. */

	PyErr_Print();
	PyThreadState_Clear(tstate);
	PyThreadState_Swap(save_tstate);
	PyThreadState_Delete(tstate);
	PyInterpreterState_Delete(interp);

	return NULL;
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:56,代码来源:pythonrun.c


示例9: End

 void End()
 {
     PyEval_AcquireLock();
     PyThreadState_Swap( NULL );
     PyThreadState_Clear( mainThreadState );
     PyThreadState_Delete( mainThreadState );
     //PyEval_Restore( mainThreadState );
     Py_Finalize();
     started = ScriptEngine::HasBegun();
 }
开发者ID:nszhsl,项目名称:pylon,代码行数:10,代码来源:scriptengine.cpp


示例10: 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


示例11: 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


示例12: thread_PyThread_start_new_thread

static PyObject *
thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
{
	PyObject *func, *args, *keyw = NULL;
	struct bootstate *boot;
	long ident;

	if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3,
		               &func, &args, &keyw))
		return NULL;
	if (!PyCallable_Check(func)) {
		PyErr_SetString(PyExc_TypeError,
				"first arg must be callable");
		return NULL;
	}
	if (!PyTuple_Check(args)) {
		PyErr_SetString(PyExc_TypeError,
				"2nd arg must be a tuple");
		return NULL;
	}
	if (keyw != NULL && !PyDict_Check(keyw)) {
		PyErr_SetString(PyExc_TypeError,
				"optional 3rd arg must be a dictionary");
		return NULL;
	}
	boot = PyMem_NEW(struct bootstate, 1);
	if (boot == NULL)
		return PyErr_NoMemory();
	boot->interp = PyThreadState_GET()->interp;
	boot->func = func;
	boot->args = args;
	boot->keyw = keyw;
	boot->tstate = _PyThreadState_Prealloc(boot->interp);
	if (boot->tstate == NULL) {
		PyMem_DEL(boot);
		return PyErr_NoMemory();
	}
	Py_INCREF(func);
	Py_INCREF(args);
	Py_XINCREF(keyw);
	PyEval_InitThreads(); /* Start the interpreter's thread-awareness */
	ident = PyThread_start_new_thread(t_bootstrap, (void*) boot);
	if (ident == -1) {
		PyErr_SetString(ThreadError, "can't start new thread");
		Py_DECREF(func);
		Py_DECREF(args);
		Py_XDECREF(keyw);
		PyThreadState_Clear(boot->tstate);
		PyMem_DEL(boot);
		return NULL;
	}
	return PyLong_FromLong(ident);
}
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:53,代码来源:_threadmodule.c


示例13: PyThreadState_Clear

void pybase::FreeThreadState()
{
    flext::thrid_t id = flext::GetThreadId();
    PyThrMap::iterator it = pythrmap.find(id);
    if(it != pythrmap.end()) {
        // clear out any cruft from thread state object
        PyThreadState_Clear(it->second);
        // delete my thread state object
        PyThreadState_Delete(it->second);
        // delete from map
        pythrmap.erase(it);
    }
}
开发者ID:McAlyster,项目名称:py,代码行数:13,代码来源:pybase.cpp


示例14: glfwMakeContextCurrent

void python_taskqueue::run( GLFWwindow *Context, rendertask_sequence &Tasks, threading::condition_variable &Condition, std::atomic<bool> &Exit ) {

    glfwMakeContextCurrent( Context );
    // create a state object for this thread
    PyEval_AcquireLock();
    auto *threadstate { PyThreadState_New( m_mainthread->interp ) };
    PyEval_ReleaseLock();

    render_task *task { nullptr };

    while( false == Exit.load() ) {
        // regardless of the reason we woke up prime the spurious wakeup flag for the next time
        Condition.spurious( true );
        // keep working as long as there's any scheduled tasks
        do {
            task = nullptr;
            // acquire a lock on the task queue and potentially grab a task from it
            {
                std::lock_guard<std::mutex> lock( Tasks.mutex );
                if( false == Tasks.data.empty() ) {
                    // fifo
                    task = Tasks.data.front();
                    Tasks.data.pop_front();
                }
            }
            if( task != nullptr ) {
                // swap in my thread state
                PyEval_RestoreThread( threadstate );
                {
                    // execute python code
                    task->run();
                    error();
                }
                // clear the thread state
                PyEval_SaveThread();
            }
            // TBD, TODO: add some idle time between tasks in case we're on a single thread cpu?
        } while( task != nullptr );
        // if there's nothing left to do wait until there is
        // but check every now and then on your own to minimize potential deadlock situations
        Condition.wait_for( std::chrono::seconds( 5 ) );
    }
    // clean up thread state data
    PyEval_AcquireLock();
    PyThreadState_Swap( nullptr );
    PyThreadState_Clear( threadstate );
    PyThreadState_Delete( threadstate );
    PyEval_ReleaseLock();
}
开发者ID:firleju,项目名称:maszyna,代码行数:49,代码来源:PyInt.cpp


示例15: PyEval_AcquireLock

void KviPythonInterpreter::done()
{
	if(!m_pThreadState)return;
	// grab the lock
	PyEval_AcquireLock();
	// swap my thread state out of the interpreter
	PyThreadState_Swap(NULL);
	// clear out any cruft from thread state object
	PyThreadState_Clear(m_pThreadState);
	// delete my thread state object
	PyThreadState_Delete(m_pThreadState);
	// release the lock
	PyEval_ReleaseLock();
	m_pThreadState = 0;
}
开发者ID:kartagis,项目名称:KVIrc,代码行数:15,代码来源:libkvipythoncore.cpp


示例16: PythonModule_Destroy

int PythonModule_Destroy( PythonModule* Self )
{
  if( Self != NULL )  
  {
    PyEval_AcquireLock();
  
    PyThreadState_Swap(NULL);
    PyThreadState_Clear(Self->CurrentThreadState);
    PyThreadState_Delete(Self->CurrentThreadState);

    PyEval_ReleaseLock();
  }

  free( Self );
}
开发者ID:BackupTheBerlios,项目名称:easyconnect-svn,代码行数:15,代码来源:pythonmodule.c


示例17: PyInterpreterState_Clear

void
PyInterpreterState_Clear(PyInterpreterState *interp)
{
    PyThreadState *p;
    HEAD_LOCK();
    for (p = interp->tstate_head; p != NULL; p = p->next)
        PyThreadState_Clear(p);
    HEAD_UNLOCK();
    Py_CLEAR(interp->codec_search_path);
    Py_CLEAR(interp->codec_search_cache);
    Py_CLEAR(interp->codec_error_registry);
    Py_CLEAR(interp->modules);
    Py_CLEAR(interp->modules_reloading);
    Py_CLEAR(interp->sysdict);
    Py_CLEAR(interp->builtins);
}
开发者ID:Av3ng3,项目名称:Lamobo-D1s,代码行数:16,代码来源:pystate.c


示例18: pass_to_motor_v_multi_thread

gpointer
pass_to_motor_v_multi_thread(gpointer args){

	PyEval_AcquireLock();
	PyInterpreterState * mainInterpreterState = mainThreadState->interp;
	PyThreadState * myThreadState = PyThreadState_New(mainInterpreterState);
	PyThreadState_Swap(myThreadState);

	pass_to_motor(args);

	PyThreadState_Swap(NULL);
	PyThreadState_Clear(myThreadState);
	PyThreadState_Delete(myThreadState);
	PyEval_ReleaseLock();

	return NULL;
}
开发者ID:amogrid,项目名称:redcurrant,代码行数:17,代码来源:c2python.c


示例19: interpreterFree

void interpreterFree(Interpreter *interpreter) {

	//PyEval_AcquireThread(interpreter->threadPythonState);
	//PyEval_RestoreThread(interpreter->threadPythonState);

	PyEval_RestoreThread(interpreter->threadPythonState);

	Py_DECREF(interpreter->pdict);

	//Py_EndInterpreter(interpreter->threadPythonState);
	PyThreadState_Clear(interpreter->threadPythonState);

	PyEval_SaveThread();

	//PyEval_SaveThread();
	//PyEval_ReleaseLock();

}
开发者ID:maxrosan,项目名称:Broker,代码行数:18,代码来源:interpreter.c


示例20: CPyStreamWrapper_Free

static void
CPyStreamWrapper_Free (CPyStreamWrapper *wrapper)
{
    if (!wrapper)
    {
        PyErr_SetString (PyExc_ValueError, "wrapper must not be NULL");
        return;
    }

#ifdef WITH_THREAD
    PyThreadState_Clear (wrapper->thread);
    PyThreadState_Delete (wrapper->thread);
#endif
    Py_XDECREF (wrapper->seek);
    Py_XDECREF (wrapper->tell);
    Py_XDECREF (wrapper->write);
    Py_XDECREF (wrapper->read);
    Py_XDECREF (wrapper->close);
    PyMem_Free (wrapper);
    return;
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:21,代码来源:streamwrapper.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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