468,321 Members | 1,811 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

Halt, stop, quit, exit?

Does Python have a command that just stops all processing?

Simon
Jul 18 '05 #1
5 198007
Simon Faulkner wrote:
Does Python have a command that just stops all processing?


The 'exit' function in the 'sys' module.

-- Gerhard

Jul 18 '05 #2
On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
<ne**@titanic.co.uk> wrote:
Does Python have a command that just stops all processing?


Yes : sys.exit (value)

See the library docs for details.

However, IMO this is normally the wrong thing. I would normally raise
an exception, and the outer level of processing would have a try block
that catches all exceptions (by name for those which can be
anticipated) reporting details of why the program stopped.

Should you decide that later that you only want to abort part of your
app (e.g. to go back to the main menu), an exception can handle this
quite naturally.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #3
Stephen Horne wrote:
On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
<ne**@titanic.co.uk> wrote:
Does Python have a command that just stops all processing?
Yes : sys.exit (value)

See the library docs for details.

However, IMO this is normally the wrong thing. I would normally raise
an exception,


....and that's what sys.exit does on your behalf: it raises the
built-in exception SystemExit. If you choose to use a raise
statement explicitly, you can then also use your own exception
classes, subclassed from the system-provided ones, for finer
grained control. Admittedly, however, such needs are typically
rather advanced ones; for many applications, such fine-grained
control may well not be necessary.
and the outer level of processing would have a try block
that catches all exceptions (by name for those which can be
anticipated) reporting details of why the program stopped.

Should you decide that later that you only want to abort part of your
app (e.g. to go back to the main menu), an exception can handle this
quite naturally.


Yes, but you can choose to do that with SystemExit as well, if you
wish. Stylistically, there is something to be said both for and
against, of course.
Alex

Jul 18 '05 #4
Alex Martelli <al***@aleax.it> writes:
Stephen Horne wrote:
On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
<ne**@titanic.co.uk> wrote:
Does Python have a command that just stops all processing?


Yes : sys.exit (value)

See the library docs for details.

However, IMO this is normally the wrong thing. I would normally raise
an exception,


...and that's what sys.exit does on your behalf: it raises the
built-in exception SystemExit. If you choose to use a raise

[...]

But if you (Simon) really want to just exit unconditionally, it's

os._exit(code)
John
Jul 18 '05 #5
Simon Faulkner wrote:

Does Python have a command that just stops all processing?


Do you want to clean up open file handles and such, including
properly freeing up any held resources, before terminating
the application? Or are you looking for the ugliest, dirtiest,
fastest way out, regardless of the damage it might cause?

Choose between sys.exit() or os._exit() as needed.

-Peter
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Mike Maxwell | last post: by
4 posts views Thread by Vladislav Moltchanov | last post: by
6 posts views Thread by bruce | last post: by
1 post views Thread by =?Utf-8?B?VGFvZ2U=?= | last post: by
1 post views Thread by =?Utf-8?B?bWFnZWxsYW4=?= | last post: by
3 posts views Thread by ghd | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.