how to stop python...

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

    how to stop python...

    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

    -bruce

  • Alex Martelli

    #2
    Re: how to stop python...

    bruce <bedouglas@eart hlink.netwrote:
    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...
    import sys

    sys.exit()


    Alex

    Comment

    • Simon Forman

      #3
      Re: how to stop python...

      bruce wrote:
      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
      >
      -bruce
      What you want is sys.exit()
      See: http://docs.python.org/lib/module-sys.html

      Comment

      • Paul McGuire

        #4
        Re: how to stop python...

        "bruce" <bedouglas@eart hlink.netwrote in message
        news:mailman.77 13.1151900654.2 7775.python-list@python.org ...
        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
        >
        -bruce
        >
        (From the interactive Python prompt:)

        import sys
        dir(sys)
        ['__displayhook_ _', '__doc__', '__excepthook__ ', '__name__', '__stderr__',
        '__st
        din__', '__stdout__', '_getframe', 'api_version', 'argv',
        'builtin_module _names'
        , 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook',
        'dllhand
        le', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix',
        'executab
        le', 'exit', 'getcheckinterv al', 'getdefaultenco ding',
        'getfilesysteme ncoding',
        'getrecursionli mit', 'getrefcount', 'getwindowsvers ion', 'hexversion',
        'maxint',
        'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks',
        'path_importer_ cach
        e', 'platform', 'prefix', 'ps1', 'ps2', 'setcheckinterv al', 'setprofile',
        'setre
        cursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'version',
        'version_info
        ', 'warnoptions', 'winver']

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

        help(sys.exit)

        Help on built-in function exit in module sys:

        exit(...)
        exit([status])

        Exit the interpreter by raising SystemExit(stat us).
        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).


        sys.exit()

        Voila!

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




        Comment

        • John Machin

          #5
          Re: how to stop python...

          On 3/07/2006 2:27 PM, bruce wrote:
          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...
          >
          Inter alia, sys.exit() and a functional Shift key.

          Comment

          • cmdrrickhunter@yaho.com

            #6
            Re: how to stop python...

            Wow, so many people with the same solution... where's the creativity
            folks?

            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!

            Comment

            • Paul Rubin

              #7
              Re: how to stop python...

              "cmdrrickhunter @yaho.com" <conrad.ammon@g mail.comwrites:
              Wow, so many people with the same solution... where's the creativity
              folks?
              >
              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!

              Comment

              Working...