sys.exit and exceptions (newbie question)

Thomas Wouters thomas at
Fri Feb 2 00:25:51 CET 2001

On Thu, Feb 01, 2001 at 05:18:38PM +0000, Victor Muslin wrote:

> What is a pythonic idiom for forcing an immediate program termination?
> sys.exit() does not do it, because it throws a SystemExit exception,
> so if it is called within a try block, a generic except block is still
> executed. 

You can use sys._exit(). This exits in a very abortive way -- right away,
dropping everything it's doing, without doing any kind of cleanup. In
general it's better to avoid unqualified except: clauses, and avoid code
that uses it (unless, of course, they reraise the exception if they can't
handle it.)

Thomas Wouters <thomas at>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list