[pygtk] Help: Problems with threads and pygtk

Brian dol-sen at telus.net
Thu Oct 5 13:21:29 WST 2006

On Wed, 2006-04-10 at 18:58 -0700, David Hirschfield wrote:
> I've run into a serious problem using threads with pygtk, and I was 
> hoping someone could give me suggestions.
> My program is a pygtk interface with a "processor" thread that pulls 
> from a safely synchronized queue of "requests" and processes each one.
> Seems simple, and it should have been...but it freezes solid when I run 
> it. Not a traceback of any kind, the interface and the python 
> interpreter freeze.
> I've checked all the things that should be obvious problems:
> I'm calling:
> gobject.threads_init()
> gtk.gdk.threads_init()
> before gtk.main() is called
> There is no race condition or blocking call causing everything to get stuck.
> The thread's only interaction with the rest of the program is via the  
> Queue.Queue object that keeps the requests to be processed.
> I've stepped through with pdb and it freezes in a completely innocuous 
> place in the code (during a loop where I append to a list).
> The freeze occurs in slightly different places depending on what kind of 
> debugging code I put in, changes to the order of things, etc...so it 
> feels like it's some kind of corruption in the interpreter stack.
> Running the processor thread in a dummy app without the pygtk part never 
> freezes up.
> Running the pygtk app with a non-threaded processor, which just 
> sequentially runs the requests and waits till they complete, never 
> freezes up.
> I'm at my wit's end here...I know threads are just asking for trouble, 
> and usually I avoid them, but circumstances here basically require 
> threading (all the request time is spent waiting on different kinds of 
> IO). The setup was so simple, I figured I couldn't possibly run into 
> trouble...yet here I am.
> So, anyone have any idea what could cause the entire python interpreter 
> to freeze solid? Are there known issues with pygtk and python threads 
> that I should be aware of? Is there some way to verify that the 
> interpreter stack is not getting screwed up somehow?
> Any help at this point would really be useful,
> -Dave

Try this dispatcher.py module for ideas of where you may be going wrong.
Use the dispatcher-example for how to use it for inter-thread

It has worked very well for our app and eliminated a number of problems.

Brian <dol-sen at telus.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dispatcher.py
Type: text/x-python
Size: 1251 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20061004/cf252d9c/dispatcher.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dispatcher-example.py
Type: text/x-python
Size: 3377 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20061004/cf252d9c/dispatcher-example.py

More information about the pygtk mailing list