Repost: Problem with embedded call...

Yogi Parish parish at imes.mavt.ethz.ch
Sat May 5 15:54:58 CEST 2001


Hello all,

I have a problem with a program that calls a python routine many times
over and over again.
Unfortunately, after some time, there seem to be problems that are
somehow to the reference count
management. The routine runs satisfactory ca. 1000 times and then fails
at various points.

I would be happy if somebody could help me out with the following
code...

/**** BEGIN SNIPPET *****/

PyInitialize()  <-- done elsewhere

 PyObject *pmod = NULL, *pfunc = NULL;
 PyObject *ppar = NULL, *pargs = NULL;


  pmod = PyImport_ImportModule("testmodule");
  pfunc = PyObject_GetAttrString(pmod, "testfunction");

float x=0.0, y=1.0;
pargs = Py_BuildValue("ff", x, y); // Build the args

 ppar  = PyObject_CallObject( pfunc, pargs );

 if (ppar==NULL) {
  fprintf( file, "ppar is NULL %d \n",counter++);
 }

if (PyArg_Parse(ppar, "(ff)", &x, &y ) == 0 )
  fprintf ( file, "PyArgParse Problem\n");

 Py_XDECREF(pargs);
 Py_XDECREF(ppar);
// Py_XDECREF(pfunc);
// Py_XDECREF(pmod);  No effect on the program if those two lines are
uncommented or not

/*** END SNIPPET ***/

This part of the routine (part of a calculation) runs ok for many
passes, but after some
time pfunc is not callable and the PyObject_CallObject returns
NULL (obviously). The rest of the code should be OK.

If I use this routine not from within the calling program but as a
standalone
program, it runs fine (at least for 10000000 calls).

I have tried every combination of DECREFs I could think of... Can
anybody
point me towards some explanatory texts/tools for debugging stuff like
this/
theories what went wrong?

thank you very much for help
yp






More information about the Python-list mailing list