Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
2.6 and sys.exit()
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
hetchkay  
View profile  
 More options Nov 12, 11:07 pm
Newsgroups: comp.lang.python
From: hetchkay <hetch...@gmail.com>
Date: Thu, 12 Nov 2009 20:07:15 -0800 (PST)
Local: Thurs, Nov 12 2009 11:07 pm
Subject: 2.6 and sys.exit()
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".

Is there any way I can get 2.6 to behave like 2.5?

Thank you for your help,

Regards,
H. Krishnan


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
r  
View profile  
 More options Nov 12, 11:22 pm
Newsgroups: comp.lang.python
From: r <rt8...@gmail.com>
Date: Thu, 12 Nov 2009 20:22:38 -0800 (PST)
Local: Thurs, Nov 12 2009 11:22 pm
Subject: Re: 2.6 and sys.exit()
On Nov 12, 10:07 pm, hetchkay <hetch...@gmail.com> wrote:

Look here ;-)
http://docs.python.org/library/exceptions.html#exceptions.SystemExit

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
r  
View profile  
 More options Nov 12, 11:26 pm
Newsgroups: comp.lang.python
From: r <rt8...@gmail.com>
Date: Thu, 12 Nov 2009 20:26:43 -0800 (PST)
Local: Thurs, Nov 12 2009 11:26 pm
Subject: Re: 2.6 and sys.exit()
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".


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hetchkay  
View profile  
 More options Nov 12, 11:32 pm
Newsgroups: comp.lang.python
From: hetchkay <hetch...@gmail.com>
Date: Thu, 12 Nov 2009 20:32:38 -0800 (PST)
Local: Thurs, Nov 12 2009 11:32 pm
Subject: Re: 2.6 and sys.exit()
Hello,

Thanks for your help.

I know what SystemExit is. In 2.5 as well SystemExit is raised when
sys.exit() is called. For example:
try:
  import sys
  sys.exit(0)
except SystemExit:
  print "system exit raised"
  raise

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.

Regards,
Krishnan


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Yeung  
View profile  
 More options Nov 12, 11:50 pm
Newsgroups: comp.lang.python
From: John Yeung <gallium.arsen...@gmail.com>
Date: Thu, 12 Nov 2009 20:50:39 -0800 (PST)
Local: Thurs, Nov 12 2009 11:50 pm
Subject: Re: 2.6 and sys.exit()
On Nov 12, 11:22 pm, r <rt8...@gmail.com> wrote:

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Yeung  
View profile  
 More options Nov 13, 12:02 am
Newsgroups: comp.lang.python
From: John Yeung <gallium.arsen...@gmail.com>
Date: Thu, 12 Nov 2009 21:02:56 -0800 (PST)
Local: Fri, Nov 13 2009 12:02 am
Subject: Re: 2.6 and sys.exit()
On Nov 12, 11:32 pm, hetchkay <hetch...@gmail.com> 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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ned Deily  
View profile  
 More options Nov 13, 12:10 am
Newsgroups: comp.lang.python
From: Ned Deily <n...@acm.org>
Date: Thu, 12 Nov 2009 21:10:32 -0800
Local: Fri, Nov 13 2009 12:10 am
Subject: Re: 2.6 and sys.exit()
In article
<008aa7ef-b945-4f70-b5e4-def66546e...@2g2000prl.googlegroups.com>,

Perhaps you don't want to be using the -i option?

"-i

When a script is passed as first argument or the -c option is used,
enter interactive mode after executing the script or the command ..."

http://docs.python.org/using/cmdline.html#generic-options

If you don't want the interpreter to gain control on exit, don't use -i
when you run the script.

--
 Ned Deily,
 n...@acm.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hetchkay  
View profile  
 More options Nov 13, 12:28 am
Newsgroups: comp.lang.python
From: hetchkay <hetch...@gmail.com>
Date: Thu, 12 Nov 2009 21:28:04 -0800 (PST)
Local: Fri, Nov 13 2009 12:28 am
Subject: Re: 2.6 and sys.exit()
On Nov 13, 9:50 am, John Yeung <gallium.arsen...@gmail.com> wrote:

I can understand the behavior from a '-i' point of view. My
requirement is somewhat different. Consider a geometry tool that can
be used to create objects, merge objects etc. I have python 'commands'
for doing any of these operations and for saving the objects to a
file. The user could write a file containing a set of commands (in
python format) and load this file in the GUI. Optionally, one of the
commands could be to exit in which case the GUI should shut down. I am
using 'execfile' to execute the file, and this does not exit if the
user has used sys.exit (or even if I expose a command called 'Exit'
which calls sys.exit).

May be I should not be using execfile but I am not sure what else I
should use. The user-written file could contain loops and other
constructs as well.

-Krishnan


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hetchkay  
View profile  
 More options Nov 13, 1:19 am
Newsgroups: comp.lang.python
From: hetchkay <hetch...@gmail.com>
Date: Thu, 12 Nov 2009 22:19:41 -0800 (PST)
Local: Fri, Nov 13 2009 1:19 am
Subject: Re: 2.6 and sys.exit()
On Nov 13, 10:28 am, hetchkay <hetch...@gmail.com> wrote:

Hi,

I had been starting my application with -i option. I have removed this
now and made a few other changes and things work OK now.

Thanks to everyone who helped in this.

Regards,
Krishnan


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google