[pygtk] PyGTK Thread problem

Antoon Pardon Antoon.Pardon at rece.vub.ac.be
Wed Apr 25 17:49:12 WST 2007


On Sun, Apr 15, 2007 at 04:39:01AM +0000, Funky Fred wrote:
> 
> 
> Just to throw the idea out there:
> 
> You can use a hybrid between idle_add & threads.
> I built  a gui with threads that build a data structure, and invoke 
> callbacks on an update queue thread that mostly sleeps, but occasionally 
> wakes up and checks for pending updates. If there are updates pending, it 
> invokes a callback on the main (gui) class. Since I occasionally got weird 
> lock-ups having the update thread invoke a callback that calls gtk methods 
> in another thread (I think because it doesn't actually get executed in that 
> other thread), I just have the update thread invoke a callback that updates 
> a flag in the gui (gtk) thread, and use a gtk idle func (via idle_add) that 
> checks the update flag, and updates the gui as necessary.
> 
> A bit intricate, I guess, but it works, no lock-ups, and the gui updates 
> nicely.
> 
> The only real catch to pygtk, threads, and python, is that pythons thread 
> management is .. lacking. There is no real way to signal threads to 
> shutdown. So if someone closes the gui, the best you can do is invoke a 
> callback on the other thread that updates a flag, they hopefully check that 
> in time to shutdown before the gui closes and/or you exit python. This can 
> be problematic if your background threads do computationally intense stuff 
> and don't necessarily check their "die" flag in time.

Well I once wrote the following, to allow threads raising exceptions
in each other.

  http://groups.google.be/group/comp.lang.python/msg/5833130893cee567?hl=nl&

Maybe the idea is usefull for you.

-- 
Antoon Pardon


More information about the pygtk mailing list