[pygtk] Can't run PyGTK more than once from embedded Python

Andrew Lentvorski bsder at allcaps.org
Tue Jan 10 05:48:31 WST 2006


Romain Behar wrote:

> Unfortunately, it's not possible to have a single
> interpreter. For example, more than one document can
> be opened and each of them can have an interpreter
> instance. Every other Python library tested works
> properly with multiple interpreters.

That's because those libraries don't have much/any global state and 
independently executing threads.  UI libraries are a different ball of wax.

>'pygtk' module
> doesn't complain, only 'gtk' one does. If the issue
> comes from the gtk extension modules being initialized
> multiple times, I'll add a bug to the tracker.

Careful.  What you are doing is ... unusual, at least.

Having multiple pygtk instances means that you have multiple Gtk event 
loops.  This is not good.  You are going to have weird problems in the 
UI event systems (things like cut and paste between windows, close 
systems, etc.).

You really might want to rethink this architecture.

You might want to make a global Python interpreter which initializes and 
then calls your current C code as an extension module.  Then, the C code 
can call *back* into the global Python interpreter when it needs Python.

It shouldn't be that much extra code and it means that you don't have to 
rewrite the entire application.

-a




More information about the pygtk mailing list