Popular C++ recipes tagged "boost"http://code.activestate.com/recipes/langs/cpp/tags/boost/2014-11-20T20:00:27-08:00ActiveState Code RecipesBoost::Python callback triggered from Non-Python created threads (C++)
2014-11-20T20:00:27-08:00Tomáš Rampashttp://code.activestate.com/recipes/users/4179816/http://code.activestate.com/recipes/578967-boostpython-callback-triggered-from-non-python-cre/
<p style="color: grey">
C++
recipe 578967
by <a href="/recipes/users/4179816/">Tomáš Rampas</a>
(<a href="/recipes/tags/boost/">boost</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Consider we have virtual/abstract C++ class that's fully implemented in Python. And for some sake of necessity we have a callback method (e.g. as some sort of event) that is being triggered from different thread on C++ side.
In such case corresponding callback methods have to manage GIL state via PyGILState_STATE.
So the resulting C++ callback class definition will look like follows (notice that Python method calls are wrapped up with GIL state handling code).</p>