Hello,<br><br>I'm trying to call Python routines from C/C++. These routines must intereact in a multi-thread environment.<br> I mean that routine A will loop waiting for a condition of routine B.<br><br>This condition are coded in C so I don't need routine A running in the same interpreter of routine B.
<br><br>I tried using:<br><br> PyEval_AcquireLock();<br> PyInterpreterState* mainInterpreterState = mainThreadState->interp;<br> PyThreadState * myThreadState = PyThreadState_New(mainInterpreterState);<br><br> PyThreadState_Swap(myThreadState);
<br><br>... Call Python code here<br><br> PyThreadState_Swap(NULL);<br> PyEval_ReleaseLock();<br><br><br>Obviosly, I called thread initialization code in the main thread like <a href="http://www.linuxjournal.com/article/3641" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.linuxjournal.com/article/3641</a><br>The problem with this code is that I hold the interpreter lock when calling routine A or B so they cannot run simultaneous and that is a requierement for me (as I explained before). It executes some code of the routine I called but then it hungs.
<br> If I release the lock before calling the Python code it doesn´t work neither somhow.<br><br>Then I tried to create an interpreter for each thread. It is not desirable but it's acceptable:<br><br> PyEval_AcquireLock();
<br>PyThreadState* myThreadState = Py_NewInterpreter();<br> PyThreadState_Swap(myThreadState); <br>PyEval_ReleaseLock();<br><br>... Call Python code here<br><br> PyEval_AcquireLock();<br> PyThreadState_Swap(NULL);<br> Py_EndInterpreter(myThreadState);
<br>PyEval_ReleaseLock();<br><br><br>But it doesn't work. It seems that it requieres to take the lock to call Python code. If I comment the PyEval_ReleaseLock line and PyEval_AcquireLock pair it calls other threads before hunging.
<br><br>I saw some threads talking about some similar situations and I saw no answer to this.<br> <br>This issue remains unsolved?<br><br><br>Thanks on advance,<br>Pablo<br><br>--<br><a href="http://www.nektra.com">http://www.nektra.com
</a><br>