Tkinter programming problem

klappnase klappnase at web.de
Fri Aug 8 06:52:07 EDT 2003


Alex Martelli <aleax at aleax.it> wrote in message news:<dmtYa.28539$an6.1003165 at news1.tin.it>...



> > IDLE 1.0      
> > >>> import sys
> > >>> sys.exit(23)
> > 
> > Traceback (most recent call last):
> >   File "<pyshell#1>", line 1, in -toplevel-
> >     sys.exit(23)
> > SystemExit: 23
> > >>> 
> 
> As you see, with the IDLE 1.0 which comes with Python 2.3, the
> exception raised by sys.exit is captured and displayed as such
> [and similarly if sys.exit is called from a module run within
> the IDLE session, rather than directly at the IDLE prompt].
> 
Oh, that is interesting, my IDLE (python-2.2.2) exits on this.
Does this happen with sys.exit(0) too?



> Often one may want to do some kind of clean-up at that point, but you
> may achieve that with a try/finally around the mainloop call (putting
> the cleanup code in the finally clause, of course).
> 
Seems like you mean something like:

def quitcmd():
    mainwindow.quit()
    do_this()
    do_that()

If this is what you meant, what is the problem with:

def exitcmd():
    do_this()
    do_that()
    sys.exit(0)

I do not think that there is much difference in the behavior of these.
May be if I launched the application from a menu and the do_that()
function does something really stupid that causes an endless loop, I
think with quitcmd() it might occur that the window is closed and I
think "Fine, the application is shut down" but the buggy do_that() is
still running in the background. With exitcmd() this won't happen, the
window will not close before do_that() comes to an end, so I will see
that there is something wrong.

Best regards

Michael




More information about the Python-list mailing list