Embedded Python:: C/Python: Is Py_Finalize() necessary between embedded function calls?
Hi, I am developing an application where I have Python embedded in C functions using the C/Python API to execute commands. My question stems from my need to preserve a PyObject to pass between these Python embedded C functions. My question is: do I have to call Py_Finalize() at the end of each Python embedded C function? The abstract structure of my code looks like this: PyObject *po; main() { po = py_function_1(); // some C code in the middle here... po = py_function_2(po); // some more C code here... } In my implementation of py_function_1 and py_function_2 do I have to call Py_Initialize() and Py_Finalize at the beginning and end of each of the two functions? Or can I just call Py_Initialize at the beginning of py_function_1 and then call Py_Finalize() at the end of py_function_2? Thank You. SP
On Fri, Feb 23, 2007 at 04:24:19AM -0800, Sydney Pang wrote:
do I have to call Py_Finalize() at the end of each Python embedded C function?
As far I understand you only need to call Py_Initialize() and Py_Finalize() once per every embedded interpreter, not for an every function. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
participants (2)
-
Oleg Broytmann
-
Sydney Pang