473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

callback cashing python

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;
}

Oct 18 '06 #1
0 865

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mickel Grönroos | last post by:
Hi! I'm fiddling with Python for Windows (normally using Linux) and as a part of that I want to try to make a simple word frequency list generator to be used in conjunction with Microsoft Word....
5
by: Max Powers | last post by:
I've spent an interesting day searching the web for help with calling OCaml functions from a python program and have come to the newsgroup for some advice (unfortunately I'm learning both languages...
6
by: Marian Aldenhövel | last post by:
Hi, I am using the FMOD audio-library with the pyFMOD python bindings. pyFMOD uses ctypes. It is possible to register callback functions with FMOD that are called at certain points in the...
1
by: scott.manton | last post by:
I'm a new user of the Python C interface. I would like to know if it is possible to put items on a standard python Queue object in C, and pop them from Python. Does the Python/C interface...
5
by: Francois De Serres | last post by:
Hiho, could somebody please enlighten me about the mechanics of C callbacks to Python? My domain is more specifically callbacks from the win32 API, but I'm not sure that's where the problem...
0
by: Francois De Serres | last post by:
Hiho, When there's an unhandled exception in my extension-module's-callback-into-Python-function-object, I get a GPF and Python exits. When the exception is being handled within the callback...
5
by: Linan | last post by:
Hi, In javascript, code could be written like this: .... var _p=XMLHttpRequest(); _p.open('GET',url,true); _p.send(null); _p.onreadystateChange=function(){
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
3
by: catsclaw | last post by:
I can't for the life of me figure out how to set a callback in Python. I have a class, which wraps another class. The second class needs a callback assigned. I don't want to use globals for it....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.