Halt, stop, quit, exit?

Discussion in 'Python' started by Simon Faulkner, Oct 13, 2003.

  1. Does Python have a command that just stops all processing?

    Simon
     
    Simon Faulkner, Oct 13, 2003
    #1
    1. Advertising

  2. On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
    <> 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, Oct 13, 2003
    #2
    1. Advertising

  3. Simon Faulkner wrote:
    > Does Python have a command that just stops all processing?


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

    -- Gerhard
     
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Oct 13, 2003
    #3
  4. Stephen Horne wrote:

    > On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
    > <> 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, Oct 13, 2003
    #4
  5. Simon Faulkner

    John J. Lee Guest

    Alex Martelli <> writes:

    > Stephen Horne wrote:
    >
    > > On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
    > > <> 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
     
    John J. Lee, Oct 13, 2003
    #5
  6. Simon Faulkner

    Peter Hansen Guest

    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
     
    Peter Hansen, Oct 14, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Segall

    Where to after Exit/Quit/Logout?

    David Segall, Jan 4, 2006, in forum: HTML
    Replies:
    3
    Views:
    374
  2. Chris P.
    Replies:
    4
    Views:
    889
    Martin Bless
    Jan 30, 2005
  3. dwhall
    Replies:
    2
    Views:
    230
    dwhall
    Dec 12, 2007
  4. Lie
    Replies:
    3
    Views:
    239
    Steven D'Aprano
    Aug 23, 2008
  5. Tricky
    Replies:
    14
    Views:
    1,308
    Sean Durkin
    May 6, 2009
Loading...

Share This Page