Re: 2.6 and sys.exit()

Discussion in 'Python' started by r, Nov 13, 2009.

  1. r

    r Guest

    On Nov 12, 10:07 pm, hetchkay <> wrote:
    > Hello,
    >
    > 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
     
    r, Nov 13, 2009
    #1
    1. Advertising

  2. r

    r Guest

    PS: Python even answers questions:

    >>> import sys
    >>> help(sys.exit)

    Help on built-in function exit in module sys:

    exit(...)
    exit([status])

    Exit the interpreter by raising SystemExit(status).
    If the status is omitted or None, it defaults to zero (i.e.,
    success).
    If the status is numeric, it will be used as the system exit
    status.
    If it is another kind of object, it will be printed and the system
    exit status will be one (i.e., failure).

    Just think of Python as a programmers version of the "Magic 8 balls".
     
    r, Nov 13, 2009
    #2
    1. Advertising

  3. r

    John Yeung Guest

    On Nov 12, 11:22 pm, r <> wrote:
    > On Nov 12, 10:07 pm, hetchkay <> 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?

    John
     
    John Yeung, Nov 13, 2009
    #3
  4. r

    John Yeung Guest

    On Nov 12, 11:32 pm, hetchkay <> wrote:
    > But I don't understand why the interpreter does not exit in 2.6 but
    > does exit in 2.5. Well, I do not need to understand that but I need to
    > know how to get the interpreter to exit in 2.6.


    Well, taken at face value, I would say the answer is to not use the -i
    option. ;) But I assume you would like to be able to sometimes enter
    interactive mode after the script completes but sometimes not?

    That I don't know how to do, but I would think it is either very
    simple or impossible. Surely someone more knowledgeable will be able
    to say which it is.

    Also, if you present your reason for wanting such behavior, maybe
    people can suggest alternatives that will serve your needs, even if
    not exactly replicating what you had in 2.5.

    John
     
    John Yeung, Nov 13, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GinTon

    sys.stderr.write and sys.exit

    GinTon, Nov 23, 2006, in forum: Python
    Replies:
    5
    Views:
    588
    Dennis Lee Bieber
    Nov 24, 2006
  2. Yujo
    Replies:
    2
    Views:
    414
    Gabriel Genellina
    Apr 10, 2007
  3. Replies:
    3
    Views:
    304
    Gabriel Genellina
    Jul 13, 2007
  4. Harlin Seritt

    Sys.exit() does not fully exit

    Harlin Seritt, Feb 17, 2008, in forum: Python
    Replies:
    3
    Views:
    283
    Christian Heimes
    Feb 17, 2008
  5. Brendan

    exit() or sys.exit()

    Brendan, Jun 17, 2009, in forum: Python
    Replies:
    2
    Views:
    388
    Brendan
    Jun 17, 2009
Loading...

Share This Page