You must call PyEval_InitThreads from your initialization (and leave the GIL saved). Then you can create pthread (using boost) and call PyGILState_Ensure in this thread, then call your python PyObject_CallFunction ( PyObject_CallFunction ?), Free any return value or handle any error ( PyErr_Print ?), Release the GIL with PyGILState_Release , and let the thread die .
void *my_thread(void *arg) { PyGILState_STATE gstate; PyObject *result; gstate = PyGILState_Ensure(); if ((result = PyObject_CallFunction(func, NULL))) { Py_DECREF(result); } else { PyErr_Print(); } PyGILState_Release(gstate); return NULL; }
source share