当前位置: 首页>>代码示例>>C++>>正文


C++ PyThreadState_Clear函数代码示例

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


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


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