[Tutor] GUI die when execute sys.exit()

D-Man dsh8290@rit.edu
Wed, 27 Jun 2001 15:40:27 -0400


On Wed, Jun 27, 2001 at 09:07:02AM -0500, Peter He wrote:
| When I run it and click the button, the gui die and I got the following 
| message:
| 
|  >>> Unhandled exception while debugging...
| Traceback (most recent call last):
|    File "C:\PP2ndEd\Examples\PP2E\Gui\Intro\gui3c.py", line 9, in quit
|      import sys; sys.exit()              # retains the self+quit pair
| SystemExit

This is supposed to happen.

| I am using Pythonwin IDE from ActiveStates and windows 2000. I got
| the same problems when I run other similar examples from other books
| too.

Well, the debugger doesn't know it, but it is supposed to be that way ;-).


sys.exit() works by raising the exception 'SystemExit'.  This allows
try-finally clauses to work to perform any cleanup necessary before
the program terminates.  You expected the program to quit (gui to
die), didn't you <wink>?  If you run the program outside of the
debugger it will look fine (you won't see the stacktrace).  Oh, yeah,
I should mention that the current python IDEs (PythonWin and IDLE come
to mind) run your code in the same interpreter the IDE runs in.  If
you call sys.exit(), well, it will exit <wink>.  (I guess that's what
you meant, PythonWin died, not "the gui")

-D