- Joined
- May 25, 2010
- Messages
- 2
- Reaction score
- 0
Hello all C++/Pyhton gurus. I'm having a little big problem trying to create an application with embedded Python and C++. Here you have a function I want to be called multiple times at the same time. I'm trying to just have one interpreter but multiple threads calling a function from a script. The problem comes when calling PyObject_CallFunction() in a second or third thread crashes my application.
The reason I don't want to use multiple interpreters is I don't want to use more memory/cpu resources than what is needed.
I tried to use PyEval_InitThreads(), but it didn't help.
My questions are:
1)Can I call multiple times a phython function using only one interpreter, at the same time?
2)If so, how?
3)If not, what procedure should I take then?
Thanks.
The reason I don't want to use multiple interpreters is I don't want to use more memory/cpu resources than what is needed.
I tried to use PyEval_InitThreads(), but it didn't help.
My questions are:
1)Can I call multiple times a phython function using only one interpreter, at the same time?
2)If so, how?
3)If not, what procedure should I take then?
Thanks.
PHP:
BounceResult * BounceC(PyObject *&pFunc, PyObject *& pArgs, PyObject *& pObject, PyObject *& pMsg)
{
PyObject *pValue;
BounceResult Object;
pArgs = PyTuple_New(2);
PyTuple_SetItem(pArgs, 0, pObject);
PyTuple_SetItem(pArgs, 1, pMsg);
if(pArgs && pMsg && pObject)
{
pValue = PyObject_CallFunction(pFunc, "O", pArgs);
}
else
{
return NULL;
}
if (!pValue)
{
fprintf(stderr, "Cannot convert argument\n");
return NULL;
}
if (pValue != NULL)
{
Py_DECREF(pValue);
}
else
{
PyErr_Print();
fprintf(stderr,"Call failed\n");
return NULL;
}
return &Object;
}