473,320 Members | 1,722 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,320 software developers and data experts.

Trace KeyboardInterrupt exception?

I'm trying to find out what is eating some KeyboardInterrupt exceptions
in a fairly large program (yum). My KeyboardInterrupt handler is called
for some Ctl-C presses, but for others nothing seems to happen.
Grepping the source (what of it I've found, looking at import
statements) doesn't turn up anything likely.

My thinking is that either some "except:" clause is eating them, or some
place I haven't looked is eating them, or possibly C code is eating
them. For the first two, at least, I'd like to use a debugger to trace
KeyboardInterrupt exceptions, make sure that they're happening, and see
what is handling them. I don't see a way to trace or break on a
specific exception type in Idle. Can someone give me a hint on how to
do this? I'm willing to consider other debuggers, including gdb (DDD).
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Jun 13 '06 #1
4 2737
Tony Nelson wrote:
I'm trying to find out what is eating some KeyboardInterrupt exceptions
in a fairly large program (yum). My KeyboardInterrupt handler is called
for some Ctl-C presses, but for others nothing seems to happen. ... I'd like to use a debugger to trace
KeyboardInterrupt exceptions, make sure that they're happening, and see
what is handling them.


I don't know how to do that in Idle. You can replace the default
Ctrl-C interrupt
handler with your own and use that to inspect the current stack. For
example,
import signal
signal.getsignal(signal.SIGINT) <built-in function default_int_handler> prev_handler = signal.getsignal(signal.SIGINT)
def new_int_handler(*args): .... print "Keyboard Interrupt!"
.... traceback.print_stack()
.... prev_handler(*args)
.... signal.signal(signal.SIGINT, new_int_handler) <built-in function default_int_handler> def spin(): .... while 1: pass
.... import traceback
spin() ^CKeyboard Interrupt!
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in spin
File "<stdin>", line 3, in new_int_handler
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in spin
File "<stdin>", line 4, in new_int_handler
KeyboardInterrupt
There's no real need to call the old handler. You could "raise
KeyboardInterrupt"
or SystemExit or just ignore it, as in
count = 0
def new_int_handler(signum, frame): .... global count
.... print messages[count]
.... if count >= len(messages)-1:
.... raise KeyboardInterrupt
.... count += 1
.... messages = {0: "Sorry, did you want me to do something?", .... 1: "That's ticklish!",
.... 2: "Now, where did that off button go to....",
.... 3: "Do that again and I'll leave.",
.... 4: "Shutdown activated"}
def spin(): .... while 1: pass
.... spin() ^CTraceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in spin
KeyboardInterrupt
import signal
signal.signal(signal.SIGINT, new_int_handler) <built-in function default_int_handler>
spin() ^CSorry, did you want me to do something?
^CThat's ticklish!
^CNow, where did that off button go to....
^CDo that again and I'll leave.
^CShutdown activated
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in spin
File "<stdin>", line 5, in new_int_handler
KeyboardInterrupt


Andrew
da***@dalkescientific.com

Jun 14 '06 #2
In article <11**********************@y43g2000cwc.googlegroups .com>,
an*********@gmail.com wrote:
Tony Nelson wrote:
I'm trying to find out what is eating some KeyboardInterrupt exceptions
in a fairly large program (yum). My KeyboardInterrupt handler is called
for some Ctl-C presses, but for others nothing seems to happen.

... I'd like to use a debugger to trace
KeyboardInterrupt exceptions, make sure that they're happening, and see
what is handling them.


I don't know how to do that in Idle. You can replace the default
Ctrl-C interrupt handler with your own and use that to inspect the
current stack.


Thanky you, that helps. Interestingly, some Ctl-Cs don't get caught.
Presumably they're happening in a subprocess.

Now to see if I can get into that situation again where Ctl-C is
ignored. I need to know what's eating the exceptions. I don't think
it's a subprocess in the case I'm concerned with. I don't think yum is
threaded, but apparantly importing the tread module anywhere should keep
KeyboardInterrupt on the main thread anyway (?).

It would be nice if I could inspect the stack and find the exception
handlers. I'm using trace handlers, but their output seems somewhat
spotty and inconsistent, or maybe just confusing.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Jun 14 '06 #3
if you want to interrupt the code to find out where it is,
you can instead connect to it in gdb and get the python traceback of
each thread.
if you're interested I'll post the necesary gdb-macro for that (didn't
put it on the net yet)

Jun 15 '06 #4
In article <11*********************@u72g2000cwu.googlegroups. com>,
"ya*****@gmail.com" <ya*****@gmail.com> wrote:
if you want to interrupt the code to find out where it is,
you can instead connect to it in gdb and get the python traceback of
each thread.
if you're interested I'll post the necesary gdb-macro for that (didn't
put it on the net yet)


I think I've found the problem, using Python's Bugzilla. This appears
to be unresolved Python bug 926423, unresolved proposed patch 1102879,
don't know if anything ever came of it. See other thread.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Jun 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve Holden | last post by:
I'm mailing the list in the hope that somebody has come up with a solution to the occasional spurious "Keyboard Interrupt" exception that gets raised in the ASP environment. It's a little awkward...
8
by: Ivan Nestlerode | last post by:
Hello comp.lang.python, I am attempting to write a threaded program right now in Python (version 2.3 on Debian unstable) and the current behavior of KeyboardInterrupt is causing me grief. From...
0
by: PantherSE | last post by:
Hello, Ok, here's my situation. I have a small application that listens to messages on a UDP port. When I pass None to settimeout(), and I hit Ctrl+C to interrupt the wait my exception...
7
by: Andy Fish | last post by:
Hi, in my c# code I have something like this: try { ... } catch (Exception ex) { ... throw ex; }
2
by: Ken | last post by:
I would like to start using EventLogTraceListener, and am running into a couple of significant limitations: 1) I have found that there is no way to write EventLog entries with different...
1
by: darren kirby | last post by:
Hello all. I have a python script here which is just a wrapper for 2 or more system commands. I would estimate the program spends at least 95.5% of 'real' time running the system commands. ...
0
by: Fredrik Tolf | last post by:
Dear List, I was writing a Python extension module, including a sleeping call to poll(2), and noticed, to my great surprise (and joy), that even when blocking there, KeyboardInterrupt still...
2
by: Michael Goerz | last post by:
Hi, when I try to catch ctrl+c with except KeyboardInterrupt: pychecker tells me Catching a non-Exception object (KeyboardInterrupt)
7
by: Brendon Costa | last post by:
Hi all, I have a small python project i am working on. Basically i always have two threads. A "Read" thread that sits in a loop reading a line at a time from some input (Usually stdin) and then...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.