I've been around this question for way too long. Now I searched this and it was working for a while but it then crashed at a random place. I think that the problem is a deadlock or something.
So please, someone tell me what I'm doing wrong:
I make a global variable:
static int gil_init = 0;
At the start of the program I call
Py_Initialize()
. This start function is called multiple times in one session but sincePy_Initialize()
is a non-op if Python is already initialized I don't think there's a problem here.From three functions I make lots of calls into the Python/C API function -
py_embed(...)
(there's only one at a time calling). The next code is present in thepy_embed()
function that is called from each thread:if (!gil_init) { gil_init = 1; PyEval_InitThreads(); PyEval_SaveThread(); } state = PyGILState_Ensure(); // Call Python/C API functions... //pValue= PyObject_CallObject(pFunc, pArgs2); Crash is always given here PyGILState_Release(state);
Oh and the crash takes place in one of the functions, but not the first time I call it which is strange. That's why I said its at a random place during running time.
In theory, and based in the reference manual of the C Api it should be working.. What am I doing wrong?
Edit: I don't call Py_Finalize()
because of this problem that I had