halting execution of all modules
Andy Beall
beall at psych.ucsb.edu
Thu Sep 14 11:42:40 EDT 2000
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. I'm trying to make a module for others to "embed" in their
own modules. I need my module to be able to halt the "embedding" module
right at the point they called a certain function from within my module.
The "foo" example below is the only way I've figured out to do this:
#Embedding module
import foo
foo.go(1)
print 'Hello...'
foo.go(0)
print 'Execution halted above: This line should not get printed'
# Embedded module
#foo.py--------------------------------------------------
def go(continue):
if continue:
return
else:
unknown_symbol_to_cause_an_error
Due to backward compatibility needs of a large project, I can't simply have
foo.go() return a flag for deciding whether to continue or not.
Thanks a bunch for any ideas,
Andy-
More information about the Python-list
mailing list