473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 199195
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.