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


C++ PyEval_RestoreThread函数代码示例

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


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


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