KeybordInterrupts and friends

A

aurelien.campeas

Hello,

I have a problem with the following code fragment :

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

while True:
try:
raw_input()
except EOFError:
print "C-d"
except KeyboardInterrupt:
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()
KeyboardInterrupt

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

robert

Hello,

I have a problem with the following code fragment :

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

while True:
try:
raw_input()
except EOFError:
print "C-d"
except KeyboardInterrupt:
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()
KeyboardInterrupt

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 ?

maybe consider signal.signal(signal.SIGINT,...

-robert
 
A

aurelien.campeas

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

robert

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.

you not protected all the time during the loop

-robert
 
A

aurelien.campeas

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,196
Latest member
NevilleFer

Latest Threads

Top