Does Python have a command that just stops all processing?
Simon 5 199211
Simon Faulkner wrote: Does Python have a command that just stops all processing?
The 'exit' function in the 'sys' module.
-- Gerhard
On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
<ne**@titanic.c o.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
Stephen Horne wrote: On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner <ne**@titanic.c o.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
Alex Martelli <al***@aleax.it > writes: Stephen Horne wrote:
On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner <ne**@titanic.c o.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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 exit Python, rather than
giving the ridiculous msg
Use Ctrl-D (i.e. EOF) to exit.
The additional reason is that God intended Ctrl-D to be "scroll down", as in
vi. I have my keyboard translator set up to do something very much like
that...
|
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
execution and immediately shoot back to the calling page without running
through the rest of the code on the executed page.
im not sure if this is possible but any help would be much appreciated.
tia
|
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 invloving also other
propject data. The whole process is controlled by WIN module, which
is delivering tasks for WIN and Open VMS system trhough the text files
in common directrory ( concordant programming). This system was working
perfect when I...
|
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 do is give a command in
procedure(3) that would exit all three procedure without returning to
procedure(1) and procedure(2)
|
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 something...
thanks
| |
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 result of system(..))
If the server really needs to stop I exit with
sys.exit(0)
but if I just want it to restart (to reread all modules) I can do
sys.exit(128)
With python 2.4, if pythonscript.py could not be found, the exit value
|
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 fine. But how to do in such following
scenario: if I need to give 2 option for user,1. Quit 2. Restart. In Quit
option, I use Environment.Exit(0) to confirm the process will be stopped. In
Restart option, I can't use Environment.Exit(0) , because...
|
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. I want to stop/cancel the file io operation and return back to the
calling form.
|
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 classfile)?
And does the JVM halt when the all the java applications on the system end?
According to the documentation, the JVM halts in two situations: 1. when you terminate the java application by Ctrl+C and 2. when the 'exit' method of the System...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| | |