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


C++ PyEval_SaveThread函数代码示例

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


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

示例1: PyEval_RestoreThread

bool PythonInterpreter::runScript(const char* filename, const char* shortName) {
    PyEval_RestoreThread(state);

    PyObject* script = PyFile_FromString(const_cast<char*>(filename),
        const_cast<char*>("r"));
    if (script) {
        PyObject* ans = PyRun_File(PyFile_AsFile(script),
            const_cast<char*>(shortName),
            Py_file_input, mainNamespace, mainNamespace);
        Py_DECREF(script);

        if (ans) {
            Py_DECREF(ans);
            state = PyEval_SaveThread();
            return true;
        } else {
            PyErr_Print();
            state = PyEval_SaveThread();
            return false;
        }
    } else {
        state = PyEval_SaveThread();
        return false;
    }
}
开发者ID:WPettersson,项目名称:regina,代码行数:25,代码来源:pythoninterpreter.cpp

示例2: rpmtsCallback

static void *
rpmtsCallback(const void * hd, const rpmCallbackType what,
		         const rpm_loff_t amount, const rpm_loff_t total,
	                 const void * pkgKey, rpmCallbackData data)
{
    Header h = (Header) hd;
    struct rpmtsCallbackType_s * cbInfo = data;
    PyObject * pkgObj = (PyObject *) pkgKey;
    PyObject * args, * result;
    static FD_t fd;

    if (cbInfo->cb == Py_None) return NULL;

    /* Synthesize a python object for callback (if necessary). */
    if (pkgObj == NULL) {
	if (h) {
	    pkgObj = Py_BuildValue("s", headerGetString(h, RPMTAG_NAME));
	} else {
	    pkgObj = Py_None;
	    Py_INCREF(pkgObj);
	}
    } else
	Py_INCREF(pkgObj);

    PyEval_RestoreThread(cbInfo->_save);

    args = Py_BuildValue("(iLLOO)", what, amount, total, pkgObj, cbInfo->data);
    result = PyEval_CallObject(cbInfo->cb, args);
    Py_DECREF(args);
    Py_DECREF(pkgObj);

    if (!result) {
	die(cbInfo->cb);
    }

    if (what == RPMCALLBACK_INST_OPEN_FILE) {
	int fdno;

        if (!PyArg_Parse(result, "i", &fdno)) {
	    die(cbInfo->cb);
	}
	Py_DECREF(result);
	cbInfo->_save = PyEval_SaveThread();

	fd = fdDup(fdno);
	fcntl(Fileno(fd), F_SETFD, FD_CLOEXEC);

	return fd;
    } else
    if (what == RPMCALLBACK_INST_CLOSE_FILE) {
	Fclose (fd);
    }

    Py_DECREF(result);
    cbInfo->_save = PyEval_SaveThread();

    return NULL;
}
开发者ID:kaltsi,项目名称:rpm,代码行数:58,代码来源:rpmts-py.c

示例3: PyEval_RestoreThread

//---------------------------------------------------------
// Pass messages into the Python interpreter main thread,
// which is expected to implement an event loop around calls
// to tart_wait() to retrieve these messages.
//
void Tart::do_postMessage(QString msg) {
    // qDebug() << QThread::currentThreadId() << "Tart: do_postMessage(" << msg << ")";

    QByteArray bytes = msg.toUtf8();

    // PyGILState_STATE gil_state = PyGILState_Ensure();
    PyEval_RestoreThread(tart_pystate);

    // qDebug() << "tart_wait bytes" << bytes.size();
    PyObject * arglist = Py_BuildValue("(s#)", bytes.constData(), bytes.size());
    // ran out of memory: fail!
    if (arglist == NULL) {
        qDebug() << "Py_BuildValue() returned NULL!";
        // should probably do something more significant here
        tart_pystate = PyEval_SaveThread();
        // PyGILState_Release(gil_state);
        return;
    } else {
        // qDebug() << "postMessage() built" << arglist;
    }

    // call the callback to send message to Python
    PyObject * result = PyObject_CallObject(event_callback, arglist);
    Py_DECREF(arglist);

    // qDebug() << "callback returned" << result;

    // TODO handle exceptions from the call, either by exiting the event
    // loop (maybe only during development?) or by dumping a traceback,
    // setting a flag, and continuing on.
    bool is_SystemExit = false;

    if (result == NULL) {   // exception during call
        // qDebug() << "exception during event delivery";

        // see http://computer-programming-forum.com/56-python/a81eae52ca74e6c1.htm
        // Calling PyErr_Print() will actually terminate the process if
        // SystemExit is the exception!
        if (PyErr_ExceptionMatches(PyExc_SystemExit))
            is_SystemExit = true;
        else
            PyErr_Print();
    }
    else
        Py_DECREF(result);

    // PyGILState_Release(gil_state);
    tart_pystate = PyEval_SaveThread();

    if (is_SystemExit) {
        qDebug() << "do_post: SystemExit from delivery";
        m_thread->exit(3);
    }

    // qDebug() << QThread::currentThreadId() << "Tart: do_postMessage done";
    return;
}
开发者ID:HorizonXP,项目名称:blackberry-py,代码行数:62,代码来源:tart.cpp

示例4: qDebug

//---------------------------------------------------------
// Pass push messages into the Python interpreter main thread,
// if it has implemented an onPushReceived() method.
//
void Tart::pushReceived(const QString & id, const QByteArray & bytes, bool wantsAck) {
    qDebug() << QThread::currentThreadId() << "Tart: pushReceived" << id << wantsAck << bytes.size();

    // FIXME: this should probably be checked inside the tart_pystate context
    // where the GIL is held, not outside.
    // Ignore data if no callback has been registered.
    if (!push_callback)
        return;

    PyEval_RestoreThread(tart_pystate);

    PyObject * arglist = Py_BuildValue("(sy#i)",
        id.toUtf8().constData(),
        bytes.constData(), bytes.size(),
        wantsAck
        );
    // ran out of memory: fail!
    if (arglist == NULL) {
        qDebug() << "Py_BuildValue() returned NULL!";
        // should probably do something more significant here
        tart_pystate = PyEval_SaveThread();
        return;
    }

    // call the callback to send message to Python
    PyObject * result = PyObject_CallObject(push_callback, arglist);
    Py_DECREF(arglist);

    // TODO handle exceptions from the call, either by exiting the event
    // loop (maybe only during development?) or by dumping a traceback,
    // setting a flag, and continuing on.
    bool is_SystemExit = false;

    if (result == NULL) {   // exception during call
        // see http://computer-programming-forum.com/56-python/a81eae52ca74e6c1.htm
        // Calling PyErr_Print() will actually terminate the process if
        // SystemExit is the exception!
        if (PyErr_ExceptionMatches(PyExc_SystemExit))
            is_SystemExit = true;
        else
            PyErr_Print();
    }
    else
        Py_DECREF(result);

    tart_pystate = PyEval_SaveThread();

    if (is_SystemExit) {
        qDebug() << "do_post: SystemExit from delivery";
        m_thread->exit(3);
    }

    return;
}
开发者ID:HorizonXP,项目名称:blackberry-py,代码行数:58,代码来源:tart.cpp

示例5: call_event_hook_callback

void call_event_hook_callback(void * event)
    {
    // qDebug() << QThread::currentThreadId() << "call_event_hook_callback: begin";

    // PyGILState_STATE gil_state = PyGILState_Ensure();
    PyEval_RestoreThread(tart_pystate);

    PyObject * arglist = Py_BuildValue("(i)", event);
    // ran out of memory: fail!
    if (arglist == NULL)
        {
        qDebug() << "Py_BuildValue() returned NULL!";
        // should probably do something more significant here

        // PyGILState_Release(gil_state);
        tart_pystate = PyEval_SaveThread();
        return;
        }

    // call the callback to send message to Python
    PyObject * result = PyObject_CallObject(event_hook_callback, arglist);
    Py_DECREF(arglist);

    // TODO handle exceptions from the call, either by exiting the event
    // loop (maybe only during development?) or by dumping a traceback,
    // setting a flag, and continuing on.
    bool is_SystemExit = false;

    if (result == NULL)     // exception during call
        {
        // see http://computer-programming-forum.com/56-python/a81eae52ca74e6c1.htm
        // Calling PyErr_Print() will actually terminate the process if
        // SystemExit is the exception!
        if (PyErr_ExceptionMatches(PyExc_SystemExit))
            is_SystemExit = true;
        else
            PyErr_Print();
        }
    else
        Py_DECREF(result);

    // PyGILState_Release(gil_state);
    tart_pystate = PyEval_SaveThread();

    if (is_SystemExit)
        {
        qDebug() << "event_hook: SystemExit";
        QThread::currentThread()->exit(3);
        }

    // qDebug() << QThread::currentThreadId() << "call_event_hook_callback: end";

    return;
    }
开发者ID:HorizonXP,项目名称:blackberry-py,代码行数:54,代码来源:tart.cpp

示例6: QObject

PythonLoader::PythonLoader(QObject *parent) : QObject(parent)
{

    if (!Py_IsInitialized())
    {
        QString sysPath = QCoreApplication::applicationDirPath();
        QString programPath = sysPath + "/thirdparty/Python/bin/python3";
        wchar_t* programName = new wchar_t[programPath.length() + 1];
        programPath.toWCharArray(programName);
        programName[programPath.length()] = 0;

        Py_SetProgramName(programName);
        wprintf(L"python prefix path: %S\n", Py_GetPrefix());
        wprintf(L"python full path: %S\n", Py_GetProgramFullPath());
        Py_Initialize();
        QStringList paths = {sysPath+"/thirdparty/Python/lib/python3.4", sysPath+"/thirdparty/Python/lib/python3.4/plat-linux",
                             sysPath+"/thirdparty/Python/lib/python3.4/lib-dynload", sysPath+"/thirdparty/Python/lib/python3.4/site-packages",
                            sysPath, sysPath+"/thirdparty/Python/lib", sysPath+"/thirdparty/Python/bin"};
        QString wholePath = paths.join(":");
        PySys_SetPath(wholePath.toStdWString().c_str());

        getSipAPI();
        PyEval_InitThreads();
        PyEval_SaveThread();
    }
}
开发者ID:nxsofsys,项目名称:dice-dev,代码行数:26,代码来源:pythonloader.cpp

示例7: rpmts_SolveCallback

static int
rpmts_SolveCallback(rpmts ts, rpmds ds, const void * data)
{
    struct rpmtsCallbackType_s * cbInfo = (struct rpmtsCallbackType_s *) data;
    PyObject * args, * result;
    int res = 1;

    if (cbInfo->tso == NULL) return res;
    if (cbInfo->cb == Py_None) return res;

    PyEval_RestoreThread(cbInfo->_save);

    args = Py_BuildValue("(Oissi)", cbInfo->tso,
		rpmdsTagN(ds), rpmdsN(ds), rpmdsEVR(ds), rpmdsFlags(ds));
    result = PyEval_CallObject(cbInfo->cb, args);
    Py_DECREF(args);

    if (!result) {
	die(cbInfo->cb);
    } else {
	if (PyInt_Check(result))
	    res = PyInt_AsLong(result);
	Py_DECREF(result);
    }

    cbInfo->_save = PyEval_SaveThread();

    return res;
}
开发者ID:kaltsi,项目名称:rpm,代码行数:29,代码来源:rpmts-py.c

示例8: nis_cat

static PyObject *
nis_cat (PyObject *self, PyObject *args, PyObject *kwdict)
{
	char *domain = NULL;
	char *map;
	struct ypall_callback cb;
	struct ypcallback_data data;
	PyObject *dict;
	int err;
	static char *kwlist[] = {"map", "domain", NULL};

	if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s|s:cat",
				         kwlist, &map, &domain))
		return NULL;
	if (!domain && ((err = yp_get_default_domain(&domain)) != 0))
		return nis_error(err);
	dict = PyDict_New ();
	if (dict == NULL)
		return NULL;
	cb.foreach = (foreachfunc)nis_foreach;
	data.dict = dict;
	map = nis_mapname (map, &data.fix);
	cb.data = (char *)&data;
	data.state = PyEval_SaveThread();
	err = yp_all (domain, map, &cb);
	PyEval_RestoreThread(data.state);
	if (err != 0) {
		Py_DECREF(dict);
		return nis_error(err);
	}
	return dict;
}
开发者ID:cocoatomo,项目名称:CTPython,代码行数:32,代码来源:nismodule.c

示例9: Py_Initialize

// 초기화
CDummyClientManager::CDummyClientManager(void)
{
	g_dummyClientManager = this;

	m_highestIndex = 0;
	m_curIndex = 0;	
	m_maxLimitIndex = 999999;	

	// 파이썬 초기화
	Py_Initialize();
	PyEval_InitThreads();
	mainThreadState = PyEval_SaveThread();
	PyGILState_STATE gilState;

	gilState = PyGILState_Ensure();

	PyImport_AddModule("pythonCallbackModule");
	Py_InitModule("pythonCallbackModule", modules);

	PyRun_SimpleString("import sys\n");
	PyRun_SimpleString("sys.path.append('.\\Python')\n");
	
	PyGILState_Release( gilState );

	// 메인 스크립트 로드
	CString log = ( SetMainScript() == false ) ? L"mainscript 로드 실패" : L"mainscript 로드 성공";	
	CtesttoolDlg* dlg = (CtesttoolDlg*)AfxGetApp()->m_pMainWnd;
	dlg->addMainLog( log );
	dlg->showMainLog();
}
开发者ID:chenbk85,项目名称:job_mobile,代码行数:31,代码来源:DummyClientManager.cpp

示例10: BeginAllowThreads

void
BeginAllowThreads(PyThreadState **state)
{
    assert(state);
    assert(*state == NULL);
    (*state) = PyEval_SaveThread();
}
开发者ID:rpm-software-management,项目名称:librepo,代码行数:7,代码来源:downloader-py.c

示例11: assert

void
QPythonPriv::leave()
{
    assert(state == NULL);
    state = PyEval_SaveThread();
    mutex.unlock();
}
开发者ID:fkrull,项目名称:pyotherside,代码行数:7,代码来源:qpython_priv.cpp

示例12: redo

 void redo()
 { 
     if (!done_ && PyEval_ThreadsInitialized()) { 
         save_ = PyEval_SaveThread(); 
         done_ = true; 
     } 
 }
开发者ID:saga-project,项目名称:saga-cpp-binding-python,代码行数:7,代码来源:invoke.hpp

示例13: main

int main(int argc, char* argv[])
{
    PyEval_InitThreads();
    Py_Initialize();
    PyObject* sysPath = PySys_GetObject((char*) "path");
    PyList_Append(sysPath, PyString_FromString("."));

    PyThreadState* save = PyEval_SaveThread();

    pthread_t tid1, tid2;
    char* tname1 = "worker1";
    char* tname2 = "worker2";
    pthread_create(&tid1, NULL, &run_python_function, &tname1);
    pthread_create(&tid2, NULL, &run_python_function, &tname2);

    for (int i = 0; i < 5; i++)
    {
        printf("main thread is running\n");
        sleep(1);
    }

    stop_event = 1;
    pthread_join(tid1, NULL);
    pthread_join(tid2, NULL);

    printf("finish\n");

    PyEval_RestoreThread(save);
    Py_Finalize();

    pthread_exit(NULL);

    return 0;
}
开发者ID:wagamama,项目名称:embedding_python,代码行数:34,代码来源:tutorial-4.c

示例14: p_loop_or_dispatch

static PyObject * p_loop_or_dispatch (int dispatch, PyObject *self, PyObject *args)
{
  pcap_t * ppcap;
  thread_state ts;
  int cnt;
  int rv;
  int release_thread;
  if (!PyArg_ParseTuple(args, "liOOii", &ppcap, &cnt, &ts.pycallback, &ts.user, &ts.use_bytearray, &release_thread)) return NULL;
  Py_INCREF(ts.user);

  ts.ppcap = ppcap;
  ts.exception = 0;
  ts.release_thread = release_thread;
  if (release_thread) ts.ts = PyEval_SaveThread();

  if (dispatch)
    rv = pcap_loop(ppcap, cnt, ld_callback, (u_char *)&ts);
  else
    rv = pcap_dispatch(ppcap, cnt, ld_callback, (u_char *)&ts);

  if (release_thread) PyEval_RestoreThread(ts.ts);

  Py_DECREF(ts.user);

  if (ts.exception) return NULL;

  return Py_BuildValue("i", rv);
}
开发者ID:14gr1010,项目名称:software,代码行数:28,代码来源:pxpcap.cpp

示例15: Device_get_file

// Device.get_file {{{
static PyObject *
Device_get_file(Device *self, PyObject *args) {
    PyObject *stream, *callback = NULL, *errs;
    ProgressCallback cb;
    unsigned long fileid;
    int ret;

    ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);


    if (!PyArg_ParseTuple(args, "kO|O", &fileid, &stream, &callback)) return NULL; 
    errs = PyList_New(0);
    if (errs == NULL) { PyErr_NoMemory(); return NULL; }
    if (callback == NULL || !PyCallable_Check(callback)) callback = NULL;

    cb.obj = callback; cb.extra = stream;
    Py_XINCREF(callback); Py_INCREF(stream);
    cb.state = PyEval_SaveThread();
    ret = LIBMTP_Get_File_To_Handler(self->device, (uint32_t)fileid, data_to_python, &cb, report_progress, &cb);
    PyEval_RestoreThread(cb.state);
    Py_XDECREF(callback); Py_DECREF(stream);

    if (ret != 0) { 
        dump_errorstack(self->device, errs);
    }
    Py_XDECREF(PyObject_CallMethod(stream, "flush", NULL));
    return Py_BuildValue("ON", (ret == 0) ? Py_True : Py_False, errs);

} // }}}
开发者ID:AEliu,项目名称:calibre,代码行数:30,代码来源:libmtp.c


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