Halt, stop, quit, exit?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Faulkner

    Halt, stop, quit, exit?

    Does Python have a command that just stops all processing?

    Simon
  • Gerhard Häring

    #2
    Re: Halt, stop, quit, exit?

    Simon Faulkner wrote:[color=blue]
    > Does Python have a command that just stops all processing?[/color]

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

    -- Gerhard

    Comment

    • Stephen Horne

      #3
      Re: Halt, stop, quit, exit?

      On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
      <news@titanic.c o.uk> wrote:
      [color=blue]
      >Does Python have a command that just stops all processing?[/color]

      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

      Comment

      • Alex Martelli

        #4
        Re: Halt, stop, quit, exit?

        Stephen Horne wrote:
        [color=blue]
        > On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
        > <news@titanic.c o.uk> wrote:
        >[color=green]
        >>Does Python have a command that just stops all processing?[/color]
        >
        > Yes : sys.exit (value)
        >
        > See the library docs for details.
        >
        > However, IMO this is normally the wrong thing. I would normally raise
        > an exception,[/color]

        ....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.
        [color=blue]
        > 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.[/color]

        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

        Comment

        • John J. Lee

          #5
          Re: Halt, stop, quit, exit?

          Alex Martelli <aleax@aleax.it > writes:
          [color=blue]
          > Stephen Horne wrote:
          >[color=green]
          > > On Mon, 13 Oct 2003 13:55:19 +0100, Simon Faulkner
          > > <news@titanic.c o.uk> wrote:
          > >[color=darkred]
          > >>Does Python have a command that just stops all processing?[/color]
          > >
          > > Yes : sys.exit (value)
          > >
          > > See the library docs for details.
          > >
          > > However, IMO this is normally the wrong thing. I would normally raise
          > > an exception,[/color]
          >
          > ...and that's what sys.exit does on your behalf: it raises the
          > built-in exception SystemExit. If you choose to use a raise[/color]
          [...]

          But if you (Simon) really want to just exit unconditionally , it's

          os._exit(code)


          John

          Comment

          • Peter Hansen

            #6
            Re: Halt, stop, quit, exit?

            Simon Faulkner wrote:[color=blue]
            >
            > Does Python have a command that just stops all processing?[/color]

            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

            Comment

            Working...