multi-threaded c++ callback problem

t.buehler t.buehler at codeforge.ch
Thu May 11 20:10:52 CEST 2006


hi all,

i'm building a wrapper for a multi-threaded c++ library to use it in python. 
everything works fine except the callback.

the c++ code to call the python function:
//-----------------------------------------------------------//
void pyCallEventCallback(  CALL hCall, 
                                    LINE hLine, 
                                    CALLSTATE_MAJOR eMajor,
                                    CALLSTATE_MINOR eMinor,  
                                    PyObject* def )
{
    if( !PyCallable_Check( def ) ) 
    {
        PyErr_SetString( PyExc_TypeError, "Need a callable object!" );
        return;
    }
    printf( "EventCallback hCall: %i, hLine: %i, eMajor: %i, eMinor: %i\n", hCall, hLine, eMajor, eMinor);
    PyObject* arglist = Py_BuildValue("(iiii)", hCall, hLine, eMajor, eMinor);

    // if i comment out next  line it works!
    PyEval_CallObject( def, arglist ); 

    Py_XDECREF(arglist);    
}
//-----------------------------------------------------------//

the python callback function looks like this:
//-----------------------------------------------------------//
def callback( *args ):
    print "callback:", args
//-----------------------------------------------------------//

the soutput i get looks like this:

EventCallback hCall: 1, hLine: 1, eMajor: 2000, eMinor: 2001
callback: ( 1, 1, 2000, 2001 )
EventCallback hCall: 1, hLine: 1, eMajor: 2500, eMinor: 2501
callback: ( 1, 1, 2500, 2501 )
EventCallback hCall: 1, hLine: 1, eMajor: 8000, eMinor: 8001
an then instead of: callback: ( 1, 1, 8000, 8001)
it crashes

there are no other python interactions between the callback calls.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060511/b4341fa7/attachment.html>


More information about the Python-list mailing list