[Python-Dev] sys.exit and PYTHONINSPECT
Kevin Altis
altis@semi-retired.com
Fri, 17 Jan 2003 10:51:52 -0800
While trying some unittests I was surprised to find that the -i command-line
option would not keep the interpreter running. Bill Bumgarner pointed out to
me that "-i doesn't deal with sys.exit. The last line of the runTests()
method in the unittest module invokes sys.exit()."
Bill also suggested that if I wanted to keep the interpreter up in the case
of the unittest I could do so with:
if __name__ == '__main__':
try:
unittest.main()
except SystemExit:
pass
But the core issue to me is that if you invoke the Python interpreter
with -i, then even sys.exit shouldn't kill the interpreter, especially since
sys.exit generates an exception which can be caught. I can't think of any
other case where -i fails to keep the interpreter alive after a script
exits, whether because of an syntax or runtime error or normal termination.
The interpreter help states:
-i : inspect interactively after running script, (also PYTHONINSPECT=x)
and force prompts, even if stdin does not appear to be a terminal
So should the sys.exit behavior with the -i command-line option be
considered a bug or a feature? ;-) I'm happy to enter a report to get the
behavior changed if possible.
ka
---
Kevin Altis
altis@semi-retired.com
http://radio.weblogs.com/0102677/
http://www.pythoncard.org/