how to stop python...

Discussion in 'Python' started by bruce, Jul 3, 2006.

  1. bruce

    bruce Guest


    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...


    bruce, Jul 3, 2006
    1. Advertisements

  2. import sys


    Alex Martelli, Jul 3, 2006
    1. Advertisements

  3. bruce

    Simon Forman Guest

    What you want is sys.exit()
    Simon Forman, Jul 3, 2006
  4. bruce

    Paul McGuire Guest

    (From the interactive Python prompt:)

    import sys
    ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__',
    din__', '__stdout__', '_getframe', 'api_version', 'argv',
    , 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook',
    le', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix',
    le', 'exit', 'getcheckinterval', 'getdefaultencoding',
    'getrecursionlimit', 'getrefcount', 'getwindowsversion', 'hexversion',
    'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks',
    e', 'platform', 'prefix', 'ps1', 'ps2', 'setcheckinterval', 'setprofile',
    cursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'version',
    ', 'warnoptions', 'winver']

    (Hmmm, no mention of "stop", but perhaps "exit"???)


    Help on built-in function exit in module sys:


    Exit the interpreter by raising SystemExit(status).
    If the status is omitted or None, it defaults to zero (i.e., success).
    If the status is numeric, it will be used as the system exit status.
    If it is another kind of object, it will be printed and the system
    exit status will be one (i.e., failure).



    and now this from the "What's new in Python 2.5":
    In the interactive interpreter, quit and exit have long been strings so that
    new users get a somewhat helpful message when they try to quit:
    'Use Ctrl-D (i.e. EOF) to exit.'
    In Python 2.5, quit and exit are now objects that still produce string
    representations of themselves, but are also callable. Newbies who try quit()
    or exit() will now exit the interpreter as they expect. (Implemented by
    Georg Brandl.)


    So from the ">>>" Python prompt, instead of ^D to exit, one can type quit()
    or exit(). Or if sys has been imported, sys.exit(). From within a script,
    one can call sys.exit().

    -- Paul
    Paul McGuire, Jul 3, 2006
  5. bruce

    John Machin Guest

    Inter alia, sys.exit() and a functional Shift key.
    John Machin, Jul 3, 2006
  6. Wow, so many people with the same solution... where's the creativity

    Whenever sys.exit() doesn't work for me, I find that a good solid thump
    on the side of the computer case with a large mallet tends to do the
    job. And there's always threatening the computer with a degaussing gun!
    cmdrrickhunter, Jul 3, 2006
  7. bruce

    Paul Rubin Guest

    Paul Rubin, Jul 3, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.