473,396 Members | 2,111 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.

handling uncaught exceptions with pdb?

I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing. Of course this presumes a certain semantics for Python
exceptions (i.e. handling one involves scanning the stack twice, once
to look for a handler and again to actually unwind the stack) and I'm
not sure if it's really done that way. I do know that Lisp has a
requirement like that, though; so maybe there is hope.
Sep 10 '08 #1
5 2212
Paul Rubin <http://ph****@NOSPAM.invalidwrites:
I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing.
....

Why not use the traceback you get to show you where to change the code
around that point to add an exception handler there which calls the
debugger?
Sep 12 '08 #2
R. Bernstein schrieb:
Paul Rubin <http://ph****@NOSPAM.invalidwrites:
>I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing.
...

Why not use the traceback you get to show you where to change the code
around that point to add an exception handler there which calls the
debugger?
Because he wants to fix the issue directly in-place, and then continue,
instead of losing hours or even days of computation.

However, it's not possible AFAIK.

Diez
Sep 12 '08 #3
Paul Rubin schrieb:
I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing. Of course this presumes a certain semantics for Python
exceptions (i.e. handling one involves scanning the stack twice, once
to look for a handler and again to actually unwind the stack) and I'm
not sure if it's really done that way. I do know that Lisp has a
requirement like that, though; so maybe there is hope.
Would this work (although it probably will slow down the program)?

<snip>
import sys, pdb

def tracefunc(frame, event, arg):
if event == "exception":
pdb.set_trace()
return tracefunc

sys.settrace(tracefunc)

def test(arg):
if arg 20:
raise ValueError(arg)
return test(arg+1)

test(0)
<snip>

Thomas
Sep 12 '08 #4
"Diez B. Roggisch" <de***@nospam.web.dewrites:
R. Bernstein schrieb:
>Paul Rubin <http://ph****@NOSPAM.invalidwrites:
>>I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing.
...

Why not use the traceback you get to show you where to change the code
around that point to add an exception handler there which calls the
debugger?

Because he wants to fix the issue directly in-place, and then
continue, instead of losing hours or even days of computation.
Then proactively add exception handlers ;-)
Sep 12 '08 #5
2008/9/10 Paul Rubin <"http://phr.cx"@nospam.invalid>:
I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb?
http://code.activestate.com/recipes/65287/

--
Cheers,
Simon B.
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues | Twitter: brunns
Sep 12 '08 #6

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

Similar topics

0
by: Jeremy Fincher | last post by:
I've just converted my application to use the logging module for its logging needs (it's quite excellent, actually :)). One thing I still have to resolve, though: in many places in my application,...
3
by: Ross | last post by:
Hi, I have a message box that displays the message "Unhandled exception in Cash32.exe: 0xC000005: access violation". Is there anyway to write an exception that handles this message. For...
9
by: David B | last post by:
Why is it so difficult to report bugs to Microsoft? I have a documented bug and an small test example. I don't really see why I should have to pay to tell them about it... Anyway, the...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.