473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 985
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Sean Don | last post by:
Hello! Is it possible to make classes friends in Python? Or is it better to just stick to "Java style" .isThis, .getThat, .setThis style functions? I understand that classes are generally...
4
by: jr | last post by:
I'm currently using the msnp.py code from Manish Jethani's project. I havn't been able to get the friends list to update like it should. it works once out of about every 25 times the program loads....
11
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
6
by: (Pete Cresswell) | last post by:
I'm makeing a little DB to help manage high school class reunions. One feature I'm trying to implement is "Friends". e.g. Fred Smith is a friend of Joe Jones and Bill Anderson. We record...
11
by: zhangzhan | last post by:
hello.everyone,i am an chinese.i study in shanxi unniversity,as i like english very much,i also wanr to make friends with a foriger. .....i really don't kown what i should to say ,as i first came...
0
by: goosen_cug | last post by:
hello.everyone,i am an chinese.i study in China University of Geosiences,as i like english and C++(program) very much,i also want to make friends with a foriger to improve my english and the...
1
by: goosen_cug | last post by:
hello.everyone,i am an chinese.i study in China University of Geosiences,as i like english and C++(program) very much,i also want to make friends with a foriger to improve my english and the...
3
by: shaun roe | last post by:
Hello, I am working in a framework with certain restrictions; in particular I have a 'data' class with getter and setter methods, and a some 'filling' classes which know how to insert the data to...
1
by: KittenKoder | last post by:
Basically I'm trying to parse my friends page on MySpace. It's easy to get Page 1. I can use "MSXML2.ServerXMLHTTP" to get the page and parse all my friends. The question is, how do I get page 2...
2
by: LeXave | last post by:
Hi all I've got the following problem in my database structure : I have a table "User". Each user can have one or more friends which are users too. And I have no idea about the way I must think...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.