473,442 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Halt, stop, quit, exit?

Does Python have a command that just stops all processing?

Simon
Jul 18 '05 #1
5 199197
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.