I've finally found the bug: to run PyGTK scripts
properly, one has to create only one Python
interpreter and use it to launch all scripts. My
application was creating a new interpreter each time
it ran a new script.
The attached example showcases the bug (if it really
is). It runs a simple PyGTK script three times, the
first two with the same interpreter (which work
properly), the third script with a new interpreter
which outputs the following error:
Traceback (most recent call last):
File "<string>", line 3, in ?
File
"/usr/lib/python2.4/site-packages/gtk-2.0/gtk/__init__.py",
line 38, in ?
import gdk # this is created by the _gtk import
ImportError: No module named gdk
Cheers,
Romain
> You probably don't want to unload or call
> Py_Finalize. It would be helpful to have
> a minimal test case so we can see exactly
> what you're doing and so that others can
> reproduce the problem.
>
> John
>
__________________________________________
Yahoo! DSL Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com
#include <Python.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
char* function = "import pygtk\npygtk.require('2.0')\nimport gtk\n\nclass Base:\n\tdef __init__(self):\n\t\tself.window = gtk.Window(gtk.WINDOW_TOPLEVEL)\n\t\tself.window.connect('destroy', gtk.main_quit)\n\t\tself.window.show()\n\n\tdef main(self):\n\t\tgtk.main()\n\nprint __name__\nif __name__ == \"__main__\":\n\tbase = Base()\n\tbase.main()\n\n";
int returncode = 0;
Py_Initialize();
PyThreadState* interpreter = Py_NewInterpreter();
PyThreadState_Swap(0);
PyThreadState_Swap(interpreter);
returncode = PyRun_SimpleString(function);
PyThreadState_Swap(0);
fprintf(stderr, "Code : %d\n", returncode);
PyThreadState_Swap(interpreter);
returncode = PyRun_SimpleString(function);
PyThreadState_Swap(0);
fprintf(stderr, "Code : %d\n", returncode);
PyThreadState_Swap(interpreter);
Py_EndInterpreter(interpreter);
PyThreadState_Swap(0);
/* ---------------------------------------------------- */
Py_Initialize();
interpreter = Py_NewInterpreter();
PyThreadState_Swap(0);
PyThreadState_Swap(interpreter);
returncode = PyRun_SimpleString(function);
PyThreadState_Swap(0);
fprintf(stderr, "Code : %d\n", returncode);
PyThreadState_Swap(interpreter);
Py_EndInterpreter(interpreter);
PyThreadState_Swap(0);
return 0;
}
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/