how do I exit gracefully?

Thomas A. Bryan tbryan at python.com
Sat Oct 28 20:22:25 EDT 2000


Andrew Pierce wrote:

> execute?  I dug around the FAQ and DejaNews and found sys.exit() and
> os._exit() but both of these methods raise exceptions.  

sys.exit() should exit the program, not raise an exception.

$ python
Python 1.5.2 (#1, Apr 18 1999, 16:03:16)  [GCC pgcc-2.91.60 19981201 (egcs-1.1.1  on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> raise ValueError
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ValueError
>>> import sys
>>> sys.exit(0)
$ 

If you're not getting a traceback, you're not getting an exception.
Perhaps you called sys.exit(1) and something running your code 
(such as a web server) assumed that a non-zero exit code indicated 
an error.

---Tom



More information about the Python-list mailing list