<quote who="LDC - Pablo Endres Lozada">
>       I have my python app and it's gui (pygtk), the app
>       has it's own threads so when I exit the gui with
>       gtk.mainquit() it doesn't end all the app.
>
>       How can I see all the threads and kill them form the interface?

What I do is;

1) All thread objects get stored in a list, threads = [thread1, thread2, ...]

2) Each thread is running a loop in its run() method.  Each time the thread
executes an iteration of the loop, it checks a variable called threads_exit. 
If threads_exit == 1 then the thread breaks the loop and returns (effectively
ending the thread).

3) To quit the application, first I use gtk.mainquit(), then I set
threads_exit = 1.  Usually some of the threads are idle because there is
nothing to do... and those threads are blocked on a condition so I use
notifyAll() on the condition to wake them up.  Then I use for t in threads:
t.join() which will block until all the threads have exited, and then the app
will quit.

The most common problem with this is that an exception will happen somewhere
and a thread will die w/o releasing some locks.  Then when I try to quit the
application will hang (blocked on the join() of a stuck thread) and I use
killall -9 to force it to quit.  This can usually be avoided by using try:
except: blocks to release locks after an exception is thrown.  Using this I am
actually able to keep the application running smoothly in spite of errors.

Its a complicated solution, but it is necessary for my application.  If you
want to try it, be prepared to spend about a week getting all the threading
problems worked out. :)



---
Andrew W. Schmeder


_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to