[C++-sig] Restarting the python interpreter

Damien Gleizes gleizesd at gmail.com
Mon Jul 3 16:52:41 CEST 2006


Hello,

I am having a little problem with my embedded python interpreter. I have an
interface button wich should restart the interpreter but it has a strange
behavior. To reset the interpreter, I was calling my EndPython function, and
then the StartPython function which are like this:

EndPython() { Py_Finalize(); }

StartPython() 
{
Py_Initialize();
PyObject *pMainModule = PyImport_AddModule( "__main__" );
m_Dictionary = PyModule_GetDict( pMainModule );
PyDict_SetItemString( m_Dictionary, "__builtins__", PyEval_GetBuiltins() );
StartBindingModule();
}

In the function StartBindingModule(), I just import the module generated by swig.

In facts, when I restart the interpreter, the memory grows up, and my module is
not correctly available. Maybe is there a way to restart the interpreter by
cleaning the dictionnary? Or maybe should I Py_Decref(m_Dictionnary) but it
seems to make the program crash when calling PyFinalize().

Any suggestions?

Thank's
DaM






More information about the Cplusplus-sig mailing list