[Python-Dev] Where to put the interrupt module?

Guido van Rossum guido@python.org
Thu, 12 Jun 2003 16:35:30 -0400


> > I'm actually a bit wary of such a generalization, because
> > KeyboardInterrupt is currently the only *asynchronous* exception that
> > code needs to worry about.  There is plenty of code that gives
> > KeyboardInterrupt special treatment, typically of the form:
> > 
> >   while MoreWorkToDo:
> >       try:
> > 	  ...run a chunk of work which may raise arbitrary exceptions...
> >       except KeyboardInterrupt:
> > 	  raise # Don't keep going in this case
> >       except:
> > 	  ...report the error and continue...
> 
> What about SystemExit?

It was only an example!

What should be done with SystemExit depends on what the application is
trying to do.  In an interactive Python shell, you probably want to
re-raise it.  But in other cases, SystemExit is an error like all
others.  (For example, consider a loop that walks a directory tree and
runs testcases found in files named "test.py".)

--Guido van Rossum (home page: http://www.python.org/~guido/)