halting execution of all modules

Fredrik Lundh effbot at telia.com
Thu Sep 14 18:04:23 CEST 2000


Andy Beall wrote:
> I'm trying to figure out how to halt a module during its execution so that
> under certain conditions all lines of code after a certain point do not get
> run.  Right now I'm doing this by introducing an unhandled NameError; this
> causes the interpreter to stop wherever it was and return but it's an ugly
> way to do this.

why not just call sys.exit()?

(it's the same as "raise SystemExit", so if the user code really
wants to catch it, it can use an explicit try/except clause).

or did you mean that using exceptions for this purpose is a bad
thing?  don't worry, you'll get over it ;-)

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->




More information about the Python-list mailing list