KeyboardInterrupt not caught

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ruka_at_@fastmail.fm

    #1

    KeyboardInterrupt not caught

    Hi,
    why is KeyboardInterru pt not caught (xp)?
    import sys
    try:
    inp = sys.stdin.read( )
    except (KeyboardInterr upt, SystemExit):
    print "kbd-interr,SystemEx it"
    except EOFError:
    print "eof encountered"
    except:
    print "caught all"
    self.showtraceb ack()
    print "normal end"

    result after script startet and ^C hit:
    >ctrl_test.py
    normal end
    Traceback (most recent call last):
    File "C:\work\py_src \ctrl_test.py", line 11, in ?
    print "normal end"
    KeyboardInterru pt

    br Rudi

  • Daniel Nogradi

    #2
    Re: KeyboardInterru pt not caught

    why is KeyboardInterru pt not caught (xp)?
    import sys
    try:
    inp = sys.stdin.read( )
    except (KeyboardInterr upt, SystemExit):
    print "kbd-interr,SystemEx it"
    except EOFError:
    print "eof encountered"
    except:
    print "caught all"
    self.showtraceb ack()
    print "normal end"
    >
    result after script startet and ^C hit:
    ctrl_test.py
    normal end
    Traceback (most recent call last):
    File "C:\work\py_src \ctrl_test.py", line 11, in ?
    print "normal end"
    KeyboardInterru pt
    Hi, are you sure this is exactly what you run?
    The code above works perfectly for me and prints

    kbd-interr,SystemEx it
    normal end

    as it should upon pressing Ctrl-C (although I'm on linux not xp but
    that shouldn't matter at all).

    Comment

    • Gabriel Genellina

      #3
      Re: KeyboardInterru pt not caught

      En Fri, 16 Feb 2007 06:58:54 -0300, Daniel Nogradi <nogradi@gmail. com>
      escribió:
      >why is KeyboardInterru pt not caught (xp)?
      >
      Hi, are you sure this is exactly what you run?
      The code above works perfectly for me and prints
      >
      kbd-interr,SystemEx it
      normal end
      >
      as it should upon pressing Ctrl-C (although I'm on linux not xp but
      that shouldn't matter at all).
      I'm using XP and it works as expected too.

      --
      Gabriel Genellina

      Comment

      • Steven D'Aprano

        #4
        Re: KeyboardInterru pt not caught

        On Fri, 16 Feb 2007 01:47:43 -0800, ruka_at_ wrote:
        Hi,
        why is KeyboardInterru pt not caught (xp)?
        import sys
        try:
        inp = sys.stdin.read( )
        except (KeyboardInterr upt, SystemExit):
        print "kbd-interr,SystemEx it"
        except EOFError:
        print "eof encountered"
        I don't think you ever get an EOFError from stdin. If you type ^D
        immediately, stdin.read() returns an empty string.

        except:
        print "caught all"
        self.showtraceb ack()
        I don't imagine you'll get any other exceptions either.

        Not that it matters, but what's self?


        print "normal end"
        >
        result after script startet and ^C hit:
        >>ctrl_test.p y
        normal end
        Traceback (most recent call last):
        File "C:\work\py_src \ctrl_test.py", line 11, in ?
        print "normal end"
        KeyboardInterru pt
        It works as expected for me.

        I seem to have a vague recollection that the keyboard interrupt under
        Windows isn't ^C but something else... ^Z maybe?



        --
        Steven.

        Comment

        • Gabriel Genellina

          #5
          Re: KeyboardInterru pt not caught

          En Fri, 16 Feb 2007 07:26:09 -0300, Steven D'Aprano
          <steve@REMOVE.T HIS.cybersource .com.auescribió :
          I seem to have a vague recollection that the keyboard interrupt under
          Windows isn't ^C but something else... ^Z maybe?
          Ctrl-C is the keyboard interrupt, Ctrl-Z means EOF.

          --
          Gabriel Genellina

          Comment

          • ruka_at_@fastmail.fm

            #6
            Re: KeyboardInterru pt not caught

            On 16 Feb., 11:44, "Gabriel Genellina" <gagsl...@yahoo .com.arwrote:

            Thanks to all of you, for the fast answers.
            The code I showed you is actually the code running. I tried to catch
            eof, cause I read ^C could produce EOF (the self.showtraceb ack() was
            just a stupid cut 'n paste). But not even the except that should catch
            all exceptions is triggered.
            Thanks again,
            br Rudi

            Comment

            • ruka_at_@fastmail.fm

              #7
              Re: KeyboardInterru pt not caught

              On 16 Feb., 12:16, ruka_...@fastma il.fm wrote:
              On 16 Feb., 11:44, "Gabriel Genellina" <gagsl...@yahoo .com.arwrote:
              >
              I've tried it in cygwin, result:
              $ python.exe c:/work/py_src/ctrl_test.py
              kbd-interr,SystemEx it
              normal end
              br Rudi

              Comment

              Working...