Call backs

A

Anand K Raydu

Hi all,

I have some problems with callback mechanisms,
I have embedded python into my application and want to customize my
application through python.
It is great with respect to calling the my APIS .
Now i have a situation where one of my API calls dialog box , and upon
clicking the dialog box buttons i am invoking python callback.
most of the time callback is failing. unfortunately there is no error
message is also generated.

following is the way i am sending the callback to python & calling it
from c.

main python code:

class myClass:
def __init__(self,value):
self.value = value
def Execute(self):
import myapis
myapis.activateDialogBox()
myapis.setCallBack(self.myCallBack)
myapis.EventLoop() # this an infinate loop which just gets
all gui events & dispatches like any gui event loop

def myCallBack(self):
import myapis
myapis.doSomeThing()


my C code to get the callback

PyObject *setCallBack(PyObject *self, PyObject *args) {

PyObject *command;
int retvalue =0;

if (!PyArg_ParseTuple(args, "O:setCallBack", &command))
return NULL;

Py_XDECREF(command);
glbCallback = command; // a global python variable
}
at the time of invocation of the API i have following code

void invokeCallBack()
if( glbCallback == NULL ) return 0 ;

PyObject *arglist;
PyObject *result;

PyGILState_STATE state = PyGILState_Ensure();
arglist = Py_BuildValue("(i)", buttonValue);
result = PyEval_CallObject(glbCallback , arglist);
// The result some times in NULL indicating failure,
// I noticed that if i imort my module in the python callback it is
happening.
/
Py_XDECREF(arglist);
Py_XDECREF(result);
PyGILState_Release(state);
}

Can some one please suggest a better way of dealing it.
i want really a robust mechanism for callbacks.
Thanks & Best Regards,
Anand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top