KeybordInterrupts and friends

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aurelien.campeas@free.fr

    #1

    KeybordInterrupts and friends

    Hello,

    I have a problem with the following code fragment :

    --------------------
    import sys

    while True:
    try:
    raw_input()
    except EOFError:
    print "C-d"
    except KeyboardInterru pt:
    print "C-c"
    --------------------

    The following behaviour seems bogus to me :

    auc@musca:~$ python test.py
    C-c
    C-c
    C-d
    C-d
    Traceback (most recent call last):
    File "test.py", line 5, in ?
    raw_input()
    KeyboardInterru pt

    The crash happens when I type C-c another time (always *after* atleast
    one C-d has been issued).

    What's wrong ? My expectations ? CPython (2.3 and 2.4 on debian exhibit
    the same problem).
    Is this a FAQ ?

    Thanks,
    Aurélien.

  • robert

    #2
    Re: KeybordInterrup ts and friends

    aurelien.campea s@free.fr wrote:[color=blue]
    > Hello,
    >
    > I have a problem with the following code fragment :
    >
    > --------------------
    > import sys
    >
    > while True:
    > try:
    > raw_input()
    > except EOFError:
    > print "C-d"
    > except KeyboardInterru pt:
    > print "C-c"
    > --------------------
    >
    > The following behaviour seems bogus to me :
    >
    > auc@musca:~$ python test.py
    > C-c
    > C-c
    > C-d
    > C-d
    > Traceback (most recent call last):
    > File "test.py", line 5, in ?
    > raw_input()
    > KeyboardInterru pt
    >
    > The crash happens when I type C-c another time (always *after* atleast
    > one C-d has been issued).
    >
    > What's wrong ? My expectations ? CPython (2.3 and 2.4 on debian exhibit
    > the same problem).
    > Is this a FAQ ?[/color]

    maybe consider signal.signal(s ignal.SIGINT,.. .

    -robert

    Comment

    • aurelien.campeas@free.fr

      #3
      Re: KeybordInterrup ts and friends

      Thanks Robert.

      But I'm not trying something at all with this, only asking if it is a
      bug (and it looks like one). I suspect too, that it is related to
      signal handling.

      Cheers,
      Aurélien.

      Comment

      • robert

        #4
        Re: KeybordInterrup ts and friends

        aurelien.campea s@free.fr wrote:
        [color=blue]
        > Thanks Robert.
        >
        > But I'm not trying something at all with this, only asking if it is a
        > bug (and it looks like one). I suspect too, that it is related to
        > signal handling.
        >
        > Cheers,
        > Aurélien.[/color]

        you not protected all the time during the loop

        -robert

        Comment

        • aurelien.campeas@free.fr

          #5
          Re: KeybordInterrup ts and friends

          I know it is racey, but the bug is not the race (iow : it is not a
          matter of pressing twice C-c very quickly). It happens all the time. I
          let enough time between the key strokes to let the program wait on
          raw_input.

          Or maybe you have something else in mind. Care to expand ?

          Thanks,
          Aurélien.

          Comment

          • aurelien.campeas@free.fr

            #6
            Re: KeybordInterrup ts and friends

            Precision : it does not happen when running interactively.

            Comment

            Working...