37,718
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include <pthread.h>
#include<stdio.h>
#include<Python.h>
#include<map>
#include <sys/types.h>
#include<pthread.h>
#include<sys/syscall.h>
using namespace std;
static int iCount =0;
void* TestThreadFun(void *arg)
{
PyThreadState* mainThreadState = NULL;
PyThreadState* nts = Py_NewInterpreter();
std::string strPyPath = "/usr/local/icache/src/css/iEngineFlow/config";
std::string strTmp = "sys.path.append('" + strPyPath + "')";
int iPyRet=0;
iPyRet = PyRun_SimpleString("import sys");
if (0 != iPyRet)
{
cout<<"import sys failed !"<<endl;
}
iPyRet = PyRun_SimpleString("sys.path.append('./')");
if (0 != iPyRet)
{
cout<<"import ./ failed !"<<endl;
}
iPyRet = PyRun_SimpleString(strTmp.c_str());
if (0 != iPyRet)
{
cout<<"import "<<strTmp <<" failed !"<<endl;
}
/*
Call python Method here
*/
Py_EndInterpreter(nts);
return NULL;
}
pthread_t tid = 0;
int main()
{
Py_Initialize();
int ret = 0;
PyEval_InitThreads();
int i =0;
for (;i<2;i++)
{
std::cout<<"thread"<<i<<" begin"<<endl;
ret = pthread_create(&tid, NULL, TestThreadFun, &tid);
}
sleep(5);
PyEval_ReleaseLock();
return 0;
}