[PyQt] GUI freezing when running large function in QThread

David Boddie dboddie at trolltech.com
Tue Jul 21 19:24:26 BST 2009


On Tuesday 21 July 2009, Brent Villalobos wrote:

> Thanks for the inquires.  Like I said before, I've worked around my 
> performance issues.  Now this is only a curiosity for future projects.  
> See my comments below.
> 
> David Boddie wrote:
> > It's not obvious from your description of the problem that the GIL is the
> > main cause, though it may be - it depends what your other module is doing.
> 
> Unfortunately, I can't recreate my situation since the bottleneck was 
> caused in one of our proprietary libraries that is a python API on top 
> of a compiled C++ shared object.

Then it could be, as someone else suggested, a GIL issue. I guess you might
be able to use standard C/C++ debugging and profiling tools to see where
things get held up.

> I'm using a typical model-view-controller architecture where changes to 
> one of the GUI fields signals a controller object that will then update 
> the model object.  The model object fires off a "modelChanged" signal 
> that the controller picks up and will create and start a new validation 
> thread if one is not already running.  That validation thread accesses 
> the model object.  Is it possible, that since the model is shared 
> between the GUI and validation thread, that would be a possible 
> bottleneck?  The model is a QObject subclass since it needs to be able 
> to fire off the "modelChanged" signal.

I guess it wouldn't be a problem - I think it's usually only a cause for
concern if you're modifying data in one thread from other without using
appropriate locking mechanisms - and here you only have to avoid doing
something that causes the GUI event loop to stall.

> > Alternatively, I could imagine that, on some platforms, things that you do
> > in the validation thread might affect Qt indirectly. I have vague thoughts
> > about X11 here, but perhaps I'm just being paranoid. Which platform are
> > you running on?
> >   
> Red Hat Enterprise Linux 5.

It was only a vague feeling that maybe different parts of the application
were independently talking to X, but maybe that doesn't cause the kind of
behaviour you're describing. I don't want to send you off on a wild goose
chase. :-)

Experimenting with debuggers and profilers would seem to be a useful starting
point for further investigation.

David


More information about the PyQt mailing list