Re: [pygtk] ending application

2002-11-01 Thread Christian Reis
On Fri, Nov 01, 2002 at 11:45:53AM -0400, LDC - Pablo Endres Lozada wrote:
 
   This is a mixed question, has some python and pytk
 
   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.

As a shortcut, why not sys.exit() when you gtk.mainquit() and kill the
app outright? Okay, not as clean, but simple :)

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



Re: [pygtk] ending application

2002-11-01 Thread Rob Brown-Bayliss
On Sat, 2002-11-02 at 04:45, LDC - Pablo Endres Lozada wrote:
   This is a mixed question, has some python and pytk
 
   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?
 
   Any Ideas

From the python docs for threading.Thread:

there are no priorities, no thread groups, and threads cannot be
destroyed, stopped, suspended, resumed, or interrupted


As far as I know you cant kill them all, sys.exit() is probbly your only
choice if the threads wont abort on their own.



-- 

*  Rob Brown-Bayliss
*  =
*  zoism.org
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



Re: [pygtk] ending application

2002-11-01 Thread Andrew W. Schmeder
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/