canceling and joining threads

Antoon Pardon apardon at forel.vub.ac.be
Mon Dec 19 09:05:13 EST 2005


Op 2005-12-19, sir_alex schreef <chimaera29 at libero.it>:
> Hello everybody! I have a couple of questions about threads: the first
> is, is there the possibility to cancel a thread while it is executing
> (like the C function thread_cancel),

You can have one thread raise an exception in an other thread.
Read my answer in the "thread and alarm" thread.

> for implementing something like an
> "abort" button? And the second is, i have a GUI in which there's a
> button that launches a thread implemented using the threading module
> (creating a class which inherits from threading.Thread and overriding
> __init__ and run), i chose to use threads to avoid the problem of
> freezing my windows, but after i call classobject.start() this happens:
> if i then call classobject.join(), then the button is freezed, because
> now the button waits the end of the thread,

Well you ask the main thread to wait for the other thread to finish.
So that is normal behaviour.

> if i don't make this call
> the button releases itself (that is a good behavior) but the thread
> freezes until i give a ctrl-c in the console from which i launched my
> app. So, how can i make my button release while the thread is
> executing? (my GUI is implemented in GTK and i use libglade) (sorry for
> the length of this post...)

Some questions.

1) Did you call gtk.gdk.threads_init() ?

2) Did you call gtk or gtk.gdk calls from an other thread?

3) Are you on windows of linux?


Some introductiory text about using threads with gtk is on
http://www.pardon-sleeuwaegen.be/antoon/python/page0.html

However a lot is linux specific.


There is also a mainling list for pygtk users. You can subscribe
here:

http://www.daa.com.au/mailman/listinfo/pygtk

-- 
Antoon Pardon



More information about the Python-list mailing list