I'm trying to wrap a C++ camera frame acquisition library into Python. I'm having problems with the callback function. I call a python function from a C function with the following code:
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
result = PyObject_CallObject(my_callback, arglist);
if(result == NULL){
caller.stopLive();
}
Py_DECREF(result);
Py_DECREF(arglist);
PyGILState_Release(gstate);
The callback works fine. The problem arises when I try to stop the callback with the camera library functions. If the python callback function is short the camera library function is able to stop the callbacks, but if the python callback function takes longer the camera library function is unable to stop the callbacks and the program freezes.
Has anybody had similar problems? Do you have any suggestions about what to try?
Edit: The code for stopping the callbacks is:
static PyObject * stopcallback(PyObject *self, PyObject *args)
{
if(grabber->isListenerRegistered(pListener)){
grabber->removeListener(pListener);
while(grabber->isListenerRegistered(pListener)){
Sleep(0);
}
delete pListener;
printf("Callback stopped\n");
Py_RETURN_NONE;
}
}
I call this function from Python.