hi,

i have a multithreaded c server that calls process_method in a different 
c thread per each call.  process_method calls a python function bar in 
module foo.  function bar calls back into c.  i've removed all the type 
error handling and simplified the code to hopefully show a minimum 
amount of code.  when only one request is hitting the server at a time 
this works correctly even at fast speeds.  but as soon as a second 
request is made concurrently, the python24.dll will crash and 
session.callback() in the python code never returns.  i've tried 
wrapping the callback code in PyGILState_Ensure(), PyEval_SaveThread() 
without success.

does anyone know what i have to do to the c callback to prevent python 
from crashing?

thanks,

bryan


static void process_method(session *session)
{
     PyObject      *py_obj_session = NULL;
     PyObject      *py_mod_foo     = NULL;
     PyObject      *py_call_bar    = NULL;
     PyThreadState *py_interp      = NULL;

     py_interp = get_py_interpreter(session);
     PyEval_AcquireLock();
     PyThreadState_Swap(py_interp);
     py_obj_session = get_py_session(session);

     py_mod_foo = PyImport_ImportModule("foo");
     py_call_bar = PyObject_GetAttrString(py_mod_foo, "bar");
     PyObject_CallFunctionObjArgs(py_call_bar, py_obj_session, NULL);

     Py_XDECREF(py_call_bar);
     Py_XDECREF(py_mod_foo);
     Py_XDECREF(py_obj_session);

     PyThreadState_Swap(NULL);
     PyEval_ReleaseLock();
}


# module bar

def bar(session):
     session.callback()



/* session.callback() /*
static PyObject* callback(PyObject *self, PyObject *args)
{
     Py_INCREF(Py_None);
     return Py_None;
}

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to