Mailing List Archive

need exit from 'exec' execution
Hi all -

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
statement, 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 ? Thanks

in advance,


Anders Moe
need exit from 'exec' execution [ In reply to ]
(quick, before the clock strikes midnight, and I'm
switched back to single-process mode!)

Anders Moe <andermoe@online.no> 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

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

does what you want.

see the library reference for more info:
http://www.python.org/doc/current/lib/module-sys.html

<F href="http://www.pythonware.com/people/fredrik" />