Created
July 9, 2014 15:55
-
-
Save ludflu/7b626fa9dc54bb86ed21 to your computer and use it in GitHub Desktop.
python -> C++ callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this is the variable that will hold a reference to the python function | |
PyObject *py_callback; | |
#the following function will invoked from python to populate the call back reference | |
PyObject *set_py_callback(PyObject *callable) | |
{ | |
py_callback = callable; /* Remember new callback */ | |
return Py_None; | |
} | |
... | |
#Initialize and acquire the global interpreter lock | |
PyEval_InitThreads(); | |
#Ensure that the current thread is ready to call the Python C API | |
PyGILState_STATE state = PyGILState_Ensure(); | |
#invoke the python function | |
boost::python::call<void>(py_callback); | |
#release the global interpreter lock so other threads can resume execution | |
PyGILState_Release(state); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment