472,807 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,807 software developers and data experts.

Halt, stop, quit, exit?

Does Python have a command that just stops all processing?

Simon
Jul 18 '05 #1
5 199101
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mike Maxwell | last post by:
<vent> I see there has been traffic over the years on this gripe, so just let me vent my frustration, and add another reason why 'exit' (or possibly exit() or quit() or halt() or some such) should...
6
by: JT | last post by:
is it possible to somehow "jump out of" an ASP page that is executed from another page via the Server.Execute method? on the page being executed i have several instances where i need to stop the...
4
by: Vladislav Moltchanov | last post by:
I have developed an automatic data processing first, transferring the data from MS Access to text files, next, reading these files by SAS and creating SAS data sets and running SAS analysis...
2
by: GGerard | last post by:
Hello Is there a way to exit all running procedures with one command? Sometimes a procedure(1) will call another procedure(2) which could call a third procedure(3) and what I would like to...
6
by: bruce | last post by:
hi... perl has the concept of "die". does python have anything similar. how can a python app be stopped? the docs refer to a sys.stop.. but i can't find anything else... am i missing...
2
by: Anthon | last post by:
I have a small C program that restarts a python based server application if the exit value of the system("python -m pythonscript arg1 arg2 ...") is greater than 127 (using WEXITSTATUS on the...
1
by: =?Utf-8?B?VGFvZ2U=?= | last post by:
Hi All, When I use applcation.exit() in winForm application, the form closed, but the process is still going!! ( The debug process is still running if debug in VS IDE). Environment.Exit(0) works...
1
by: =?Utf-8?B?bWFnZWxsYW4=?= | last post by:
hi all, I have a button (stopcopy) that I want the user to cancel out of a long file copying operation. I'm not clear what I should "adding" in the sub to make this happen besides & return....
3
by: ghd | last post by:
In Windows XP when does the JVM start (JRE version 1.4 and higher)? And when does it halt? Does the JVM start when we launch a java application (or by executing on the command prompt - java...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.