need exit from 'exec' execution

Fredrik Lundh fredrik at
Wed Jun 16 23:32:26 CEST 1999

(quick, before the clock strikes midnight, and I'm
switched back to single-process mode!)

Anders Moe <andermoe at> wrote:
> My python-embedded app frequently makes use of  'exec <program-string>'.
> I'd like to create a Tk Button to halt this execution at some point, with the
> option of aborting it. The only command that comes close is the exit state-
> ment, but its to powerful - it exits from the whole app, whereas I only
> wanted a local exit from the exec's program-string. Anyone know how to
> make this kind of local exit ?

are we talking sys.exit here?  if so,

import sys

    exec "sys.exit()"
except SystemExit:
    print "got you"

does what you want.

see the library reference for more info:

<F href="" />

More information about the Python-list mailing list