2.6 and sys.exit()

John Yeung gallium.arsenide at gmail.com
Fri Nov 13 05:50:39 CET 2009

On Nov 12, 11:22 pm, r <rt8... at gmail.com> wrote:
> On Nov 12, 10:07 pm, hetchkay <hetch... at gmail.com> wrote:
> > I have the following in exit.py:
> > import sys
> > sys.exit(0)
> > I now try 'python -i exit.py':
> > In 2.5, the script exits as I would expect.
> > In 2.6, the following error is printed:
> > Traceback (most recent call last):
> >   File "exit.py", line 2, in <module>
> >     sys.exit(0)
> > SystemExit: 0
> > I couldn't find anything related to this in "What's new in 2.6".
> Look here ;-)
> http://docs.python.org/library/exceptions.html#exceptions.SystemExit

How does that answer the OP's question?  Namely, how to make 2.6
behave like 2.5?  (Even saying "You can't make 2.6 behave like 2.5"
would have been a better answer.)

Failing that, how about something that explains why 2.6 behaves
differently than 2.5, and why one of them is better or more correct
than the other?

Personally, I think 2.6's is probably the more correct behavior.
Specifically, if the point of the -i command line option is to force
interactive mode after completion of the script (which in this case
completed with sys.exit), then it should go to interactive mode
regardless of whether the script terminates "normally" or not.  I
think 2.5's behavior of allowing interactive mode to be skipped is
against the spirit of -i.  Unless -i meant something different in 2.5.

Is there some kind of environment variable to set up to control this?


More information about the Python-list mailing list