469,929 Members | 1,918 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

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

Apr 26 '06 #1
5 938
au**************@free.fr wrote:
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
Apr 26 '06 #2
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.

Apr 26 '06 #3
au**************@free.fr wrote:
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
Apr 26 '06 #4
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.

Apr 26 '06 #5
Precision : it does not happen when running interactively.

Apr 26 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Sean Don | last post: by
4 posts views Thread by jr | last post: by
6 posts views Thread by (Pete Cresswell) | last post: by
11 posts views Thread by zhangzhan | last post: by
reply views Thread by goosen_cug | last post: by
1 post views Thread by goosen_cug | last post: by
3 posts views Thread by shaun roe | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.