[PyKDE] PyQt + multiple Interpreters
Christoph Wiedemann
wiedeman at gmx.net
Mon Sep 20 09:20:34 BST 2004
> On Friday 17 September 2004 10:17 am, Christoph Wiedemann wrote:
> > Hi Phil,
> >
> > > SIP v3.x is deprecated. Try v4 see what happens.
> >
> > i've tried (sip 4.0.1) - and there are several issues arising from the
> fact
> > that i use embedded python interpreters.
> >
> > 1. i've used to link my application against libqtcmodule.so, which has
> > disappeared (renamed to qt.so). I do this in order to use
> > sipForceConvertTo_QWidget in my embedding application.
> >
> > What is the recommended way to get a QWidget pointer from a PyObject *
> in
> > an embedding application with sip 4.x ?
>
> Call sipForceConvertTo_QWidget(). It's covered in the documentation. You
> don't
> need to link against anything.
If i don't link against the qt extension module, i'll get an unresolved
symbol, if i use sipForceConvertTo_QWidget in the embedding application. Jim
Bubliz' comment might help, though.
> > 2. i couldn't use the new EnsureGIL methods (got a deadlock somewhere),
> so
> > i've used the -g switch while configuring PyQt.
>
> There are bugs in Python's thread handling that are fixed in the current
> 2.4
> alpha version and will be fixed in the next 2.3.x release. This may not be
> your problem, but it might be worth trying.
These problems were caused by the fact, that the PyGILState API expects each
thread to have exactly one PyThreadState associated with it - this wasn't
expected in PyRestoreThread API.
>
> > My main question still remains: Is there a way to control the
> ThreadState
> > PyQt acquires when calling virtual python functions? The situation is as
> > follows: i have two or more PyInterpreters in my application. I want to
> > provide a shell widget for each interpreter, which is most simply done
> with
> > PyCute. But when i type print "Hello", Hello pops up in incorrect places
> > (the wrong shell widget / or even in the application stdout).
>
> I don't really understand what you are trying to do. You either have the
> right
> thread state or the wrong one - it's not something you would want to
> control.
OK, i was slightly confused by the Python API. What i really want to do is
to control the interpreter used for the PyQt Widget (PyNewInterpreter
returns a new PyThreadState instance, so i have mixed things up). Now, i
think i've got a solution for that: I installed a C++ Event Filter for the
widget and all its children, which restores the correct interpreter for it,
i.e. set the 'interp' variable of the current ThreadState. Might not be the
most performant way, but it seems to work ...
Thanks for the help,
Christoph
More information about the PyQt
mailing list