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


C++ PyEval_InitThreads函数代码示例

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


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

示例1: main

int main(int argc, char *argv[])
{
    int err;

#ifdef __WIN32__
    //Let's make sure we're in the directory where the executable
    //is since this is required for Makehuman to function on Windows
    //Makehuman will fail to start if you're not in the same directory
    //as the executable
    TCHAR exepath[MAX_PATH];
    if (0 == GetModuleFileName(0, exepath, MAX_PATH)) {
	fprintf(stderr, "coulnd't get executable path\n");
    }
    else {
	PathRemoveFileSpec(exepath);
	SetCurrentDirectory(exepath);
    }
#endif

    Py_SetProgramName(argv[0]);
#if 0
    Py_SetPythonHome(".");
#endif
    Py_Initialize();

    if (!Py_IsInitialized())
    {
        fprintf(stderr, "Could not initialize Python\n");
        exit(EXIT_FAILURE);
    }

    PySys_SetArgv(argc, argv);

    PyEval_InitThreads();

    err = PyRun_SimpleString("execfile('makehuman.py')");

    if (err != 0)
    {
        fprintf(stderr, "Could not run main Python script\n");
        getchar();
        exit(EXIT_FAILURE);
    }

    Py_Finalize();

    return 0;
}
开发者ID:RuliLG,项目名称:makehuman,代码行数:48,代码来源:main.c

示例2: embed_init_python

void embed_init_python(void)
{
    FENTER;

#ifndef PYTHON_SO_LIB
#error "Python version needs passing in with -DPYTHON_SO_VERSION=libpython<ver>.so"
#else
#define PY_SO_LIB xstr(PYTHON_SO_LIB)
#endif

    // Don't initialise python if already running
    if (gtstate)
        return;

    void * ret = utils_dyn_open(PY_SO_LIB);
    if (!ret) {
        fprintf(stderr, "Failed to find python lib\n");
    }

    Py_SetProgramName(progname);
    Py_Initialize();                    /* Initialize the interpreter */
    PySys_SetArgvEx(1, argv, 0);
    PyEval_InitThreads();               /* Create (and acquire) the interpreter lock */

    /* Swap out and return current thread state and release the GIL */
    gtstate = PyEval_SaveThread();

    /* Before returning we check if the user wants pause the simulator thread
       such that they can attach */
    const char *pause = getenv("COCOTB_ATTACH");
    if (pause) {
        long sleep_time = strtol(pause, NULL, 10);
        if (errno == ERANGE && (sleep_time == LONG_MAX || sleep_time == LONG_MIN)) {
            fprintf(stderr, "COCOTB_ATTACH only needs to be set to ~30 seconds");
            goto out;
        }
        if ((errno != 0 && sleep_time == 0) ||
            (sleep_time <= 0)) {
            fprintf(stderr, "COCOTB_ATTACH must be set to an integer base 10 or omitted");
            goto out;
        }

        fprintf(stderr, "Waiting for %lu seconds - Attach to %d\n", sleep_time, getpid());
        sleep(sleep_time);
    }
out:
    FEXIT;
}
开发者ID:ambikeshwar1991,项目名称:cocotb,代码行数:48,代码来源:gpi_embed.c

示例3: mraa_init

mraa_init()
{
    /** Once more board definitions have been added,
     *  A method for detecting them will need to be devised.
     */
    if (plat != NULL) {
        return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
    }
#ifdef SWIGPYTHON
    // Initialise python threads, this allows use to grab the GIL when we are
    // required to do so
    Py_InitializeEx(0);
    PyEval_InitThreads();
#endif
    // detect a galileo gen2 board
    char *line = NULL;
    // let getline allocate memory for *line
    size_t len = 0;
    FILE *fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
    if (fh != NULL) {
        if (getline(&line, &len, fh) != -1) {
            if (strncmp(line, "GalileoGen2", 10) == 0) {
                platform_type = MRAA_INTEL_GALILEO_GEN2;
            } else {
                platform_type = MRAA_INTEL_GALILEO_GEN1;
            }
            free(line);
        }
        fclose(fh);
    }

    advance_func = (mraa_adv_func_t*) malloc(sizeof(mraa_adv_func_t));
    memset(advance_func, 0, sizeof(mraa_adv_func_t));

    switch(platform_type) {
        case MRAA_INTEL_GALILEO_GEN2:
            plat = mraa_intel_galileo_gen2();
            break;
        case MRAA_INTEL_GALILEO_GEN1:
            plat = mraa_intel_galileo_rev_d();
            break;
        default:
            plat = mraa_intel_galileo_rev_d();
            fprintf(stderr, "Platform not found, initialising MRAA_INTEL_GALILEO_GEN1\n");
    }

    return MRAA_SUCCESS;
}
开发者ID:alexandruradovici,项目名称:mraa,代码行数:48,代码来源:mraa.c

示例4: _py_init_interpreter

static void
_py_init_interpreter(void)
{
  if (!interpreter_initialized)
    {
      python_debugger_append_inittab();

      Py_Initialize();

      PyEval_InitThreads();
      python_log_message_init();
      PyEval_SaveThread();

      interpreter_initialized = TRUE;
    }
}
开发者ID:Achint08,项目名称:syslog-ng,代码行数:16,代码来源:python-plugin.c

示例5: 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;
	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);
		PyMem_DEL(boot);
		return NULL;
	}
	return PyInt_FromLong(ident);
}
开发者ID:1310701102,项目名称:sl4a,代码行数:47,代码来源:threadmodule.c

示例6: annoy

void annoy(int count)
{
    count = std::max(count, 0);

    if (!PyEval_ThreadsInitialized())
    {
        PyEval_InitThreads();
    }

#ifdef PRINT_DEBUG_MESSAGES
    std::cout << "checking thread pool for removal" << std::endl;
#endif
    while(count < threads.size())
    {
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "stopping thread" << std::endl;
#endif
        auto& back = threads.back();
        back.second->quit = true;
        back.first.join();
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "removing thread" << std::endl;
#endif
        threads.pop_back();
    }

#ifdef PRINT_DEBUG_MESSAGES
    std::cout << "checking thread pool for additions" << std::endl;
#endif
    while(count > threads.size())
    {
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "creating thread" << std::endl;
#endif
        threads.push_back(thread_data{});
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "setting thread" << std::endl;
#endif
        auto& back = threads.back();
        back.second = std::make_shared<thread_parms>();
        back.second->quit = false;
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "launching thread" << std::endl;
#endif
        back.first = std::thread(worker, back.second);
    }
}
开发者ID:after5cst,项目名称:python-extend-with-threads,代码行数:47,代码来源:annoymodule.cpp

示例7: main

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

    PyObject *pModule = NULL, *pClass = NULL, *pInst = NULL;
    do
    {
        PyGILState_STATE state = PyGILState_Ensure();
        {
            pModule = PyImport_ImportModule("worker");
            if (pModule == NULL) break;

            pClass = PyObject_GetAttrString(pModule, "ThreadManager");
            if (pClass == NULL) break;

            pInst = PyObject_CallObject(pClass, NULL);
            if (pInst == NULL) break;

            PyObject_CallMethod(pInst, "start_thread", NULL);
        }
        PyGILState_Release(state);

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

        state = PyGILState_Ensure();
        {
            PyObject_CallMethod(pInst, "stop_thread", NULL);
        }
        PyGILState_Release(state);

        printf("finish\n");
    } while (0);

    Py_XDECREF(pInst);
    Py_XDECREF(pClass);
    Py_XDECREF(pModule);

    Py_Finalize();
    return 0;
}
开发者ID:wagamama,项目名称:embedding_python,代码行数:47,代码来源:tutorial-3NG.c

示例8: initaudiodev

PyMODINIT_FUNC
initaudiodev(void)
{
    PyObject *m;
    
    PyEval_InitThreads();

    m = Py_InitModule3("audiodev", Module_methods, "portable audio device module based on the RtAudio project");
    if (m == NULL)
        return;

    _rtaudio = new RtAudio();
    
    ModuleError = PyErr_NewException("audiodev.error", NULL, NULL);
    Py_INCREF(ModuleError);
    PyModule_AddObject(m, "error", ModuleError);
}
开发者ID:theintencity,项目名称:py-audio,代码行数:17,代码来源:audiodev.cpp

示例9: initrtaudio

PyMODINIT_FUNC
initrtaudio(void) 
{
  PyEval_InitThreads();
  import_libnumarray();
  import_libnumeric();

  PyObject* module;
  
  if (PyType_Ready(&RtAudio_type) < 0)
    return;
  
  module = Py_InitModule3("rtaudio", rtaudio_methods,
			  "RtAudio wrapper.");

  PyRTAUDIO_SINT8 = PyLong_FromUnsignedLong(RTAUDIO_SINT8);
  PyModule_AddObject(module, "RTAUDIO_SINT8", PyRTAUDIO_SINT8);
  Py_INCREF(PyRTAUDIO_SINT8);

  PyRTAUDIO_SINT16 = PyLong_FromUnsignedLong(RTAUDIO_SINT16);
  PyModule_AddObject(module, "RTAUDIO_SINT16", PyRTAUDIO_SINT16);
  Py_INCREF(PyRTAUDIO_SINT16);

  PyRTAUDIO_SINT24 = PyLong_FromUnsignedLong(RTAUDIO_SINT24);
  PyModule_AddObject(module, "RTAUDIO_SINT24", PyRTAUDIO_SINT24);
  Py_INCREF(PyRTAUDIO_SINT24);

  PyRTAUDIO_SINT32 = PyLong_FromUnsignedLong(RTAUDIO_SINT32);
  PyModule_AddObject(module, "RTAUDIO_SINT32", PyRTAUDIO_SINT32);
  Py_INCREF(PyRTAUDIO_SINT32);

  PyRTAUDIO_FLOAT32 = PyLong_FromUnsignedLong(RTAUDIO_FLOAT32);
  PyModule_AddObject(module, "RTAUDIO_FLOAT32", PyRTAUDIO_FLOAT32);
  Py_INCREF(PyRTAUDIO_FLOAT32);

  PyRTAUDIO_FLOAT64 = PyLong_FromUnsignedLong(RTAUDIO_FLOAT64);
  PyModule_AddObject(module, "RTAUDIO_FLOAT64", PyRTAUDIO_FLOAT64);
  Py_INCREF(PyRTAUDIO_FLOAT64);
  
  Py_INCREF(&RtAudio_type);
  PyModule_AddObject(module, "RtAudio", (PyObject *)&RtAudio_type);
  
  RtAudioError = PyErr_NewException("rtaudio.RtError", NULL, NULL);
  PyModule_AddObject(module, "RtError", RtAudioError);
  Py_INCREF(RtAudioError);
}
开发者ID:RikVerschueren,项目名称:AccordionMega,代码行数:46,代码来源:rtaudiomodule.cpp

示例10: init_jpype

PyMODINIT_FUNC init_jpype()
{
	Py_Initialize();
	PyEval_InitThreads();
	  
	PyObject* module = Py_InitModule("_jpype", jpype_methods);  
	Py_INCREF(module);
	hostEnv = new PythonHostEnvironment();
	  
	JPEnv::init(hostEnv);

	PyJPMonitor::initType(module);	
	PyJPMethod::initType(module);	
	PyJPBoundMethod::initType(module);	
	PyJPClass::initType(module);	
	PyJPField::initType(module);	
}
开发者ID:Koblaid,项目名称:jpype,代码行数:17,代码来源:jpype_python.cpp

示例11: MPyEmbed_Init

void MPyEmbed_Init(void) {
	if (!PythonAvailable) {
		PythonAvailable = initlinkage();
	}
	if (!PythonAvailable) {
		return;
	}
	PyEval_InitThreads();
	Py_Initialize();

	initpydega();

	PySys_SetArgv(argc, argv);
	mainstate = PyEval_SaveThread();
	memset(threaddata, 0, sizeof(threaddata));
	threaddatalock = PyThread_allocate_lock();
}
开发者ID:Plombo,项目名称:dega,代码行数:17,代码来源:embed.c

示例12: ui_thread_create_thread

// @pymethod |PyCWinThread|CreateThread|Creates the actual thread behind the thread object.
static PyObject *
ui_thread_create_thread(PyObject *self, PyObject *args)
{
	DWORD createFlags = 0;
	UINT stackSize = 0;
	if (!PyArg_ParseTuple(args, "|li:CreateThread", &createFlags, &stackSize))
		return NULL;
	CWinThread *pThread = GetCWinThreadPtr(self);
	if (!pThread) return NULL;
	PyEval_InitThreads();
	GUI_BGN_SAVE;
	BOOL ok = pThread->CreateThread(createFlags, stackSize);
	GUI_END_SAVE;
	if (!ok)
		RETURN_ERR("CreateThread failed");
	RETURN_NONE;
}
开发者ID:malrsrch,项目名称:pywin32,代码行数:18,代码来源:win32thread.cpp

示例13: mraa_init

mraa_init()
{
    if (plat != NULL) {
        return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
    }

    uid_t proc_euid = geteuid();
    struct passwd* proc_user = getpwuid(proc_euid);

#ifdef DEBUG
    setlogmask(LOG_UPTO(LOG_DEBUG));
#else
    setlogmask(LOG_UPTO(LOG_NOTICE));
#endif

    openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
    syslog(LOG_NOTICE, "libmraa version %s initialised by user '%s' with EUID %d",
           mraa_get_version(), (proc_user != NULL) ? proc_user->pw_name : "<unknown>", proc_euid);

#ifdef SWIGPYTHON
    // Initialise python threads, this allows use to grab the GIL when we are
    // required to do so
    Py_InitializeEx(0);
    PyEval_InitThreads();
#endif
    advance_func = (mraa_adv_func_t*) malloc(sizeof(mraa_adv_func_t));
    memset(advance_func, 0, sizeof(mraa_adv_func_t));

#if defined(X86PLAT)
    // Use runtime x86 platform detection
    platform_type = mraa_x86_platform();
#elif defined(ARMPLAT)
    // Use runtime ARM platform detection
    platform_type = mraa_arm_platform();
#else
#error mraa_ARCH NOTHING
#endif

    if (plat == NULL) {
        printf("mraa: FATAL error, failed to initialise platform\n");
        return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
    }

    syslog(LOG_INFO, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), platform_type);
    return MRAA_SUCCESS;
}
开发者ID:zBMNForks,项目名称:mraa,代码行数:46,代码来源:mraa.c

示例14: initvisit

initvisit(void)
{
    if(moduleState == NULL)
    {
        moduleState = (VisItModuleState*)malloc(sizeof(VisItModuleState));
        memset(moduleState, 0, sizeof(VisItModuleState));
    }

    /* Make sure that threads are init'd */
    PyEval_InitThreads();

    /* Add the VisIt module to Python. Note that we're passing just a
     * couple of methods and then the interface that we load will
     * get the rest of the functions.
     */
    Py_InitModule("visit", visit_methods);
}
开发者ID:ahota,项目名称:visit_intel,代码行数:17,代码来源:visitfrontend.c

示例15: on_startup

static int on_startup() {
  struct stat fi;
  if (!project_app || !*project_app) {
    nxweb_log_error("python wsgi app not specified; skipping python initialization");
    return 0;
  }
  static const char* prog_name="python/nxwebpy.py";
  if (stat(prog_name, &fi)==-1) {

#ifdef NXWEB_LIBDIR
    prog_name=NXWEB_LIBDIR "/nxwebpy.py";
    if (stat(prog_name, &fi)==-1) {
#endif

      nxweb_log_error("%s is missing; skipping python initialization", prog_name);
      return 0;

#ifdef NXWEB_LIBDIR
    }
#endif

  }

  Py_SetProgramName((char*)prog_name);
  // initialize thread support
  PyEval_InitThreads();
  Py_Initialize();
  char *a[]={(char*)prog_name, (char*)project_root, (char*)project_app, (char*)virtualenv_path};
  PySys_SetArgv(4, a);
  PyObject* py_module_name=PyString_FromString(MODULE_NAME);
  assert(py_module_name);
  // save a pointer to the main PyThreadState object
  py_main_thread_state=PyThreadState_Get();
  py_module=PyImport_Import(py_module_name);
  if (!py_module || !PyModule_Check(py_module)) {
    fprintf(stderr, "can't load python module %s; check parse errors:\n", MODULE_NAME);
    PyErr_Print();
    exit(0);
  }
  Py_DECREF(py_module_name);
  py_nxweb_on_request_func=PyObject_GetAttrString(py_module, FUNC_NAME);
  assert(py_nxweb_on_request_func && PyCallable_Check(py_nxweb_on_request_func));
  // release the lock
  PyEval_ReleaseLock();
  return 0;
}
开发者ID:liexusong,项目名称:NXWEB,代码行数:46,代码来源:python.c


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