I've found a workaround for me project that I'll share.<br>The solution is to release the interpreter lock when a function of my wapper is called, I mean from Python a function of C++ is called so I released the interpreter lock and take it before returning to Python.
<br>It's important to provide Sleep functions in your C++ code. Otherwise, multi-threading will not work at all. If most of the work is done in your C++ code, using this workaround will solve the issue.<br><br>To make it easier I've wrote a class to create an instance at the beginning of each wrapped function.
<br><br>Here is the constructor / destructor:<br><br>PythonAutoLock::PythonAutoLock()<br>{<br> PythonMgr *mgr = PythonMgr::instance();<br><br> _state = PyThreadState_Get();<br> <br> PyThreadState_Swap(NULL);<br>
PyEval_ReleaseLock();<br>}<br><br>PythonAutoLock::~PythonAutoLock()<br>{<br> PythonMgr *mgr = PythonMgr::instance();<br><br> PyEval_AcquireLock();<br> PyThreadState_Swap(_state);<br>}<br><br><br>Pablo Yabo
<br>--<br><a href="http://www.nektra.com">http://www.nektra.com</a><br><br><br><div><span class="gmail_quote">On 8/13/07, <b class="gmail_sendername">Pablo Yabo</b> <<a href="mailto:pablo.yabo@gmail.com">pablo.yabo@gmail.com
</a>> wrote:</span><blockquote class="gmail_quote" style="margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; margin-left: 0.80ex; border-left-color: #cccccc; border-left-width: 1px; border-left-style: solid; padding-left: 1ex">
Hello,<br><br>I want to embed <span id="st" name="st" class="st">Python</span> in an application and use an API of the application from <span id="st" name="st" class="st">Python</span>.<br>The application uses a library that creates several threads and I the users of the application will write
<span id="st" name="st" class="st">Python</span> scripts handling this events. <br><br>The problem is that I having problems with threads. I saw that I have to PyEval_InitThreads and then PyThreadState_New and PyThreadState_Swap from the new thread but this way to solve the problem doesn't work for me because I need to let 2 or more threads run at the SAME time.
<br>The interpreter lock doesn't let them run at the same time so I'm looking for another solution. I saw Py_NewInterpreter and I tried to use it but it doesn't work if I don't keep the lock.<br><br>Can anyone help me to solve this issue or tell me 'Forget it!'?
<br><br><br>Thanks on advance,<br><span id="st" name="st" class="st">Pablo</span> Yabo<br><span class="sg">--<br><a href="http://www.nektra.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.nektra.com
</a><br></span></blockquote></div><br>