Repost: Problem with Embedded Call
Yogi Parish
parish at imes.mavt.ethz.ch
Thu May 3 14:02:35 EDT 2001
Yogi Parish wrote:
> 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.
>
> I have tried every combination of DECREFs I could think of... Can
> anybody
> point towards the light?
>
> thank you very much for help
> yp
More information about the Python-list
mailing list