[PyQt] Restarting embedded interpreter with sip generated module

martyn.gigg at stfc.ac.uk martyn.gigg at stfc.ac.uk
Thu Jan 7 13:55:20 GMT 2010


I have an application with Python embedded that contains a sip generated module that allows us to script various parts of the application.

It would be extremely helpful if we were able to restart the interpreter without restarting the application. I've called Py_Finalize() and then Py_Initialize again, which works fine. The trouble lies with the initialization of the sip generated module, in this case a function called initqti. After calling this after a restart all I see is an empty module, i.e. help(qti) gives no definitions at all.

I have tested this with a small standalone piece of code

#include <Python.h>
extern "C"
{
  void initword();
}

int main()
{
  PyImport_AppendInittab((char*)"word",initword);

  Py_Initialize();
  PyRun_SimpleString("print 'Initialized python'");
  PyRun_SimpleString("import sys; sys.path.insert(0, '.')");
  PyRun_SimpleString("import word; w = word.Word('abc'); print w.reverse()");
  PyRun_SimpleString("help(word)");
  Py_Finalize();

  Py_Initialize();
  PyRun_SimpleString("print 'Initialized python again!'");
  PyRun_SimpleString("import sys; sys.path.insert(0, '.')");
  PyRun_SimpleString("import word; w = word.Word('abc'); print w.reverse()");
  PyRun_SimpleString("help(word)");
  Py_Finalize();

}

where "word" is the same as the example module given in the sip reference documentation. I have also attached the complete example.

Is there something fundamentally incorrect about trying this or something that I don't understand about the workings of sip/python.

Many thanks,

Martyn 


-- 
Scanned by iCritical.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple_restart.tgz
Type: application/x-compressed-tar
Size: 577 bytes
Desc: simple_restart.tgz
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100107/e6551c48/attachment.bin>


More information about the PyQt mailing list