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

C++ PyEval_RestoreThread函数代码示例

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

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



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

示例1: gdbpy_readline_wrapper

static char *
gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
			char *prompt)
{
  int n;
  char *p = NULL, *p_start, *p_end, *q;
  volatile struct gdb_exception except;

  TRY_CATCH (except, RETURN_MASK_ALL)
    p = command_line_input (prompt, 0, "python");

  /* Detect user interrupt (Ctrl-C).  */
  if (except.reason == RETURN_QUIT)
    return NULL;

  /* Handle errors by raising Python exceptions.  */
  if (except.reason < 0)
    {
      /* The thread state is nulled during gdbpy_readline_wrapper,
	 with the original value saved in the following undocumented
	 variable (see Python's Parser/myreadline.c and
	 Modules/readline.c).  */
      PyEval_RestoreThread (_PyOS_ReadlineTState);
      gdbpy_convert_exception (except);
      PyEval_SaveThread ();
      return NULL;
    }

  /* Detect EOF (Ctrl-D).  */
  if (p == NULL)
    {
      q = PyMem_Malloc (1);
      if (q != NULL)
	q[0] = '\0';
      return q;
    }

  n = strlen (p);

  /* Copy the line to Python and return.  */
  q = PyMem_Malloc (n + 2);
  if (q != NULL)
    {
      strncpy (q, p, n);
      q[n] = '\n';
      q[n + 1] = '\0';
    }
  return q;
}
开发者ID:abidh,项目名称:gdb,代码行数:49,代码来源:py-gdb-readline.c


示例2: vmd_input_hook

static int vmd_input_hook() {
  if (the_app) {
    the_app->VMDupdate(1);
  }
  PyEval_RestoreThread(event_tstate);
  PyRun_SimpleString(
      "try:\n"
      "\timport Tkinter\n"
      "\twhile Tkinter.tkinter.dooneevent(Tkinter.tkinter.DONT_WAIT):\n"
      "\t\tpass\n"
      "except:\n"
      "\tpass\n");
  PyEval_SaveThread();
  return 0;
}
开发者ID:tmd-gpat,项目名称:MOLding,代码行数:15,代码来源:py_vmd.C


示例3: lock

void
interpreter_lock_impl::lock() {
	boost::mutex::scoped_lock lock(mutex_);
	while (NULL != thread_state_) {
		if (!thread_lock_count_) {
			break;
		}
		condition_.wait(lock);
	}
	if (NULL == thread_state_) {
		throw std::runtime_error("Can not acquire python interpreter lock");
	}
	PyEval_RestoreThread(thread_state_);
	thread_lock_count_++;
}
开发者ID:Leonya,项目名称:xiva,代码行数:15,代码来源:interpreter_lock.cpp


示例4: evaluator_call

static PyObject *
evaluator_call(PyFFEvaluatorObject *self, PyObject *args)
{
  PyArrayObject *coordinates = NULL;
  PyObject *gradients = NULL;
  PyObject *force_constants = NULL;
  int small_change = 0;
  gradient_function *gf = NULL;
  fc_function *fcf = NULL;
  energy_data energy;
  if (!PyArg_ParseTuple(args, "O!|OOi",
			&PyArray_Type, &coordinates,
			&gradients, &force_constants,
			&small_change))
    return NULL;
  if (gradients == Py_None)
    gradients = NULL;
  if (force_constants == Py_None)
    force_constants = NULL;
  if (gradients != NULL && !PyArray_Check(gradients)) {
    PyObject *fnptr = PyObject_CallMethod(gradients, "accessFunction", NULL);
    if (fnptr == NULL)
      return NULL;
    gf = (gradient_function *)PyCObject_AsVoidPtr(fnptr);
  }
  if (force_constants != NULL && !PyArray_Check(force_constants)) {
    PyObject *fnptr = PyObject_CallMethod(force_constants,
					  "accessFunction", NULL);
    if (fnptr == NULL)
      return NULL;
    fcf = (fc_function *)PyCObject_AsVoidPtr(fnptr);
  }
  energy.gradients = gradients;
  energy.gradient_fn = gf;
  energy.force_constants = force_constants;
  energy.fc_fn = fcf;
#ifdef WITH_THREAD
  self->tstate_save = PyEval_SaveThread();
#endif
  (*self->eval_func)(self, &energy, coordinates, small_change);
#ifdef WITH_THREAD
  PyEval_RestoreThread(self->tstate_save);
#endif
  if (energy.error)
    return NULL;
  else
    return PyFloat_FromDouble(energy.energy);
}
开发者ID:CCBatIIT,项目名称:AlGDock,代码行数:48,代码来源:MMTK_pose.c


示例5: PyEval_RestoreThread

bool PythonInterpreter::runScript(const char* code) {
    PyEval_RestoreThread(state);

    PyObject* ans = PyRun_String(const_cast<char*>(code), Py_file_input,
        mainNamespace, mainNamespace);
    if (ans) {
        Py_DECREF(ans);
        state = PyEval_SaveThread();
        return true;
    } else {
        PyErr_Print();
        PyErr_Clear();
        state = PyEval_SaveThread();
        return false;
    }
}
开发者ID:WPettersson,项目名称:regina,代码行数:16,代码来源:pythoninterpreter.cpp


示例6: PyMinqlx_Finalize

PyMinqlx_InitStatus_t PyMinqlx_Finalize(void) {
    if (!PyMinqlx_IsInitialized()) {
        DebugPrint("%s was called before being initialized!\n", __func__);
        return PYM_NOT_INITIALIZED_ERROR;
    }
    
    for (handler_t* h = handlers; h->name; h++) {
		*h->handler = NULL;
	}

    PyEval_RestoreThread(mainstate);
    Py_Finalize();
    initialized = 0;
    
    return PYM_SUCCESS;
}
开发者ID:PerpetualWar,项目名称:minqlx,代码行数:16,代码来源:python_embed.c


示例7: interpreterPrepare

void interpreterPrepare(Interpreter *interpreter) {

	//PyEval_AcquireLock();

	//interpreter->threadPythonState = Py_NewInterpreter();
	interpreter->threadPythonState = PyThreadState_New(mainPythonThread->interp);

	PyEval_RestoreThread(interpreter->threadPythonState);
	interpreter->pdict = PyDict_New();

	PyDict_SetItemString(interpreter->pdict, "__builtins__", PyEval_GetBuiltins(  ));

	PyEval_SaveThread();
	//PyEval_ReleaseThread(interpreter->threadPythonState);

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


示例8: CDDA_read_sectors

static PyObject*
CDDA_read_sectors(cdio_CDDAObject* self, PyObject *args)
{
    int16_t *raw_sector;
    int i;

    int current_sectors_position = 0;
    int sectors_read;
    int sectors_to_read;

    pcm_FrameList *sectors;
    PyThreadState *thread_state = NULL;

    if (!PyArg_ParseTuple(args, "i", &sectors_to_read))
        return NULL;

    sectors = (pcm_FrameList*)PyObject_CallMethod(self->pcm_module,
                                                  "__blank__", NULL);
    if (sectors == NULL)
        return NULL;

    if (read_callback == NULL) {
        thread_state = PyEval_SaveThread();
    }

    sectors->frames = sectors_to_read * (44100 / 75);
    sectors->channels = 2;
    sectors->bits_per_sample = 16;
    sectors->samples_length = (sectors->frames * sectors->channels);
    sectors->samples = realloc(sectors->samples,
                               sectors->samples_length * sizeof(int));

    for (sectors_read = 0; sectors_read < sectors_to_read; sectors_read++) {
        raw_sector = cdio_paranoia_read_limited(self->paranoia,
                                                &read_sector_callback,
                                                10);
        for (i = 0; i < (SECTOR_LENGTH / 2); i++) {
            sectors->samples[current_sectors_position++] = raw_sector[i];
        }
    }

    if (read_callback == NULL) {
        PyEval_RestoreThread(thread_state);
    }

    return (PyObject*)sectors;
}
开发者ID:Excito,项目名称:audiotools,代码行数:47,代码来源:cdiomodule.c


示例9: PyEval_RestoreThread

void Effect::run()
{
	// switch to the main thread state and acquire the GIL
	PyEval_RestoreThread(_mainThreadState);

	// Initialize a new thread state
	_interpreterThreadState = Py_NewInterpreter();

	// import the buildtin Hyperion module
	PyObject * module = PyImport_ImportModule("hyperion");

	// add a capsule containing 'this' to the module to be able to retrieve the effect from the callback function
	PyObject_SetAttrString(module, "__effectObj", PyCapsule_New(this, nullptr, nullptr));

	// add ledCount variable to the interpreter
	PyObject_SetAttrString(module, "ledCount", Py_BuildValue("i", _imageProcessor->getLedCount()));

	// add a args variable to the interpreter
	PyObject_SetAttrString(module, "args", json2python(_args));

	// decref the module
	Py_XDECREF(module);

	// Set the end time if applicable
	if (_timeout > 0)
	{
		_endTime = QDateTime::currentMSecsSinceEpoch() + _timeout;
	}

	// Run the effect script
	FILE* file = fopen(_script.c_str(), "r");
	if (file != nullptr)
	{
		PyRun_SimpleFile(file, _script.c_str());
	}
	else
	{
		std::cerr << "EFFECTENGINE ERROR: Unable to open script file " << _script << std::endl;
	}
	fclose(file);

	// Clean up the thread state
	Py_EndInterpreter(_interpreterThreadState);
	_interpreterThreadState = nullptr;
	PyEval_ReleaseLock();
}
开发者ID:7h30n3,项目名称:hyperion,代码行数:46,代码来源:Effect.cpp


示例10: qDebug

PythonModules::~PythonModules()
{
    qDebug() << "Destroying " << this;

    unloadModules();

    PyEval_RestoreThread(pymainstate);

    cleaningPyObjs();

    Py_Finalize();

#if defined(Q_OS_WIN) && !defined(BUILD_PYTHON_3)
    // this value is only used for the Python 2.7 module
    delete [] pythonPath;
#endif //Q_OS_WIN && !BUILD_PYTHON_3
}
开发者ID:metrodango,项目名称:pip3line,代码行数:17,代码来源:pythonmodules.cpp


示例11: DeleteDummyClient

CDummyClientManager::~CDummyClientManager(void)
{
	DeleteDummyClient( 0, m_highestIndex - 1 );
	
	while(1)
	{
		int count = dummyClientToDeleteList.size();
		if( count == 0 )
		{
			break;
		}
		DeleteThreadEndedClient();
		Sleep(50);
	}
	
	PyEval_RestoreThread( mainThreadState );
	Py_Finalize();
}
开发者ID:chenbk85,项目名称:job_mobile,代码行数:18,代码来源:DummyClientManager.cpp


示例12: data_to_python

static uint16_t data_to_python(void *params, void *priv, uint32_t sendlen, unsigned char *data, uint32_t *putlen) {
    PyObject *res;
    ProgressCallback *cb;
    uint16_t ret = LIBMTP_HANDLER_RETURN_OK;

    cb = (ProgressCallback *)priv;
    *putlen = sendlen;
    PyEval_RestoreThread(cb->state);
    res = PyObject_CallMethod(cb->extra, "write", "s#", data, (Py_ssize_t)sendlen);
    if (res == NULL) {
        ret = LIBMTP_HANDLER_RETURN_ERROR;
        *putlen = 0;
        PyErr_Print();
    } else Py_DECREF(res);

    cb->state = PyEval_SaveThread();
    return ret;
}
开发者ID:AEliu,项目名称:calibre,代码行数:18,代码来源:libmtp.c


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


示例14: pylcm_handle_timeout

waits for and dispatches the next incoming message\n\
");

static PyObject *
pylcm_handle_timeout (PyLCMObject *lcm_obj, PyObject *arg)
{
    int timeout_millis = PyInt_AsLong(arg);
    if (timeout_millis == -1 && PyErr_Occurred())
        return NULL;
    if (timeout_millis < 0) {
        PyErr_SetString (PyExc_ValueError, "invalid timeout");
        return NULL;
    }

    dbg(DBG_PYTHON, "pylcm_handle_timeout(%p, %d)\n", lcm_obj, timeout_millis);

    if (lcm_obj->saved_thread_state) {
        PyErr_SetString (PyExc_RuntimeError,
            "Simultaneous calls to handle() / handle_timeout() detected");
        return NULL;
    }
    lcm_obj->saved_thread_state = PyEval_SaveThread();
    lcm_obj->exception_raised = 0;

    dbg(DBG_PYTHON, "calling lcm_handle_timeout(%p, %d)\n", lcm_obj->lcm,
        timeout_millis);
    int status = lcm_handle_timeout(lcm_obj->lcm, timeout_millis);

    // Restore the thread state before returning back to Python.  The thread
    // state may have already been restored by the callback function
    // pylcm_msg_handler()
    if (lcm_obj->saved_thread_state) {
      PyEval_RestoreThread(lcm_obj->saved_thread_state);
      lcm_obj->saved_thread_state = NULL;
    }

    if (lcm_obj->exception_raised) { return NULL; }
    if (status < 0) {
        PyErr_SetString (PyExc_IOError, "lcm_handle_timeout() returned -1");
        return NULL;
    }
    return PyInt_FromLong(status);
}
开发者ID:GArlington,项目名称:lcm,代码行数:43,代码来源:pylcm.c


示例15: py_cli_state_trace_callback

static void py_cli_state_trace_callback(enum tevent_trace_point point,
					void *private_data)
{
	struct py_cli_state *self = (struct py_cli_state *)private_data;
	struct py_cli_thread *t = self->thread_state;

	switch(point) {
	case TEVENT_TRACE_BEFORE_WAIT:
		assert(t->py_threadstate == NULL);
		t->py_threadstate = PyEval_SaveThread();
		break;
	case TEVENT_TRACE_AFTER_WAIT:
		assert(t->py_threadstate != NULL);
		PyEval_RestoreThread(t->py_threadstate);
		t->py_threadstate = NULL;
		break;
	default:
		break;
	}
}
开发者ID:Alexander--,项目名称:samba,代码行数:20,代码来源:pylibsmb.c


示例16: ld_callback

static void ld_callback (u_char * my_thread_state, const struct pcap_pkthdr * h, const u_char * data)
{
  thread_state * ts = (thread_state *)my_thread_state;
  PyObject * args;
  PyObject * rv;
  if (ts->release_thread)
    PyEval_RestoreThread(ts->ts);
#ifndef NO_BYTEARRAYS
  if (ts->use_bytearray)
  {
    args = Py_BuildValue("ONlli",
                         ts->user,
                         PyByteArray_FromStringAndSize((const char *)data, h->caplen),
                         (long)h->ts.tv_sec,
                         (long)h->ts.tv_usec,
                         h->len);
  }
  else
#endif
  {
    args = Py_BuildValue("Os#lli",
                         ts->user,
                         data, h->caplen,
                         (long)h->ts.tv_sec,
                         (long)h->ts.tv_usec,
                         h->len);
  }
  rv = PyEval_CallObject(ts->pycallback, args);
  Py_DECREF(args);
  if (rv)
  {
    Py_DECREF(rv);
  }
  else
  {
    ts->exception = 1;
    pcap_breakloop(ts->ppcap);
  }
  if (ts->release_thread)
    ts->ts = PyEval_SaveThread();
}
开发者ID:14gr1010,项目名称:software,代码行数:41,代码来源:pxpcap.cpp


示例17: MPyEmbed_Fini

void MPyEmbed_Fini(void) {
	int i;
	if (!PythonAvailable) {
		return;
	}
	MPyEmbed_Exiting = 1;
	for (i = 0; i < THREADS; i++) {
		if (VALID(threaddata[i])) {
			PyThread_acquire_lock(threaddata[i].exitlock, WAIT_LOCK);
			PyThread_free_lock(threaddata[i].exitlock);
		} else if (threaddata[i].exitlock != 0) {
			PyThread_free_lock(threaddata[i].exitlock);
		}

	}
	memset(threaddata, 0, sizeof(threaddata));

	PyEval_RestoreThread(mainstate);
	Py_Finalize();
	MPyEmbed_Exiting = 0;
}
开发者ID:Plombo,项目名称:dega,代码行数:21,代码来源:embed.c


示例18: cleanupPy

static void cleanupPy(void *junk)
{
    /* safe because exit hooks are only run once, from a single thread */
    static int done;

    if(done) return;
    done = 1;

    PyThreadState *state = PyGILState_GetThisThreadState();

    PyEval_RestoreThread(state);

    if(PyRun_SimpleString("import devsup\n"
                          "devsup._fini(iocMain=True)\n"
    )) {
        PyErr_Print();
        PyErr_Clear();
    }

    Py_Finalize(); // calls python atexit hooks
}
开发者ID:mdavidsaver,项目名称:pyDevSup,代码行数:21,代码来源:setup.c


示例19: CDDA_read_sector

static PyObject*
CDDA_read_sector(cdio_CDDAObject* self)
{
    int16_t *raw_sector;
    int i;

    int current_sector_position = 0;

    pcm_FrameList *sector;
    PyThreadState *thread_state = NULL;

    sector = (pcm_FrameList*)PyObject_CallMethod(self->pcm_module,
                                                 "__blank__", NULL);
    if (sector == NULL)
        return NULL;

    if (read_callback == NULL) {
        thread_state = PyEval_SaveThread();
    }

    sector->frames = 44100 / 75;
    sector->channels = 2;
    sector->bits_per_sample = 16;
    sector->samples_length = (sector->frames * sector->channels);
    sector->samples = realloc(sector->samples,
                              sector->samples_length * sizeof(int));

    raw_sector = cdio_paranoia_read_limited(self->paranoia,
                                            &read_sector_callback,
                                            10);
    for (i = 0; i < (SECTOR_LENGTH / 2); i++) {
        sector->samples[current_sector_position++] = raw_sector[i];
    }

    if (read_callback == NULL) {
        PyEval_RestoreThread(thread_state);
    }

    return (PyObject*)sector;
}
开发者ID:Excito,项目名称:audiotools,代码行数:40,代码来源:cdiomodule.c


示例20: PyGILState_Ensure

PyGILState_STATE
PyGILState_Ensure(void)
{
    int current;
    PyThreadState *tcur;
    /* Note that we do not auto-init Python here - apart from
       potential races with 2 threads auto-initializing, pep-311
       spells out other issues.  Embedders are expected to have
       called Py_Initialize() and usually PyEval_InitThreads().
    */
    assert(autoInterpreterState); /* Py_Initialize() hasn't been called! */
    tcur = (PyThreadState *)PyThread_get_key_value(autoTLSkey);
    if (tcur == NULL) {
        /* At startup, Python has no concrete GIL. If PyGILState_Ensure() is
           called from a new thread for the first time, we need the create the
           GIL. */
        PyEval_InitThreads();

        /* Create a new thread state for this thread */
        tcur = PyThreadState_New(autoInterpreterState);
        if (tcur == NULL)
            Py_FatalError("Couldn't create thread-state for new thread");
        /* This is our thread state!  We'll need to delete it in the
           matching call to PyGILState_Release(). */
        tcur->gilstate_counter = 0;
        current = 0; /* new thread state is never current */
    }
    else
        current = PyThreadState_IsCurrent(tcur);
    if (current == 0)
        PyEval_RestoreThread(tcur);
    /* Update our counter in the thread-state - no need for locks:
       - tcur will remain valid as we hold the GIL.
       - the counter is safe as we are the only thread "allowed"
         to modify this value
    */
    ++tcur->gilstate_counter;
    return current ? PyGILState_LOCKED : PyGILState_UNLOCKED;
}
开发者ID:Alkalit,项目名称:cpython,代码行数:39,代码来源:pystate.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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