[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] short-circuiting runtime errors/exceptions in python debugger.


I was debugging a very long script that I was not all that familiar
with, and I was doing my familiar routine of being very careful in
evaluating expressions to make sure that I didn't hit such statements

TypeError: unsupported operand type(s) for +: 'int' and 'str'

anyways the script has a runtime of hours, so this was tedious work,
and I hit one-too-many times where I missed a condition and had to
start all over again.

So that got me thinking: the main problem with exceptions and runtime
errors is that they short-circuit the program context. You have this
context, but you can't change it to avoid the failure; ie: with

1. aa = 'a'
2. bb = 1 + a
3. print bb

you'll never get to line 3 if you go through line 2. If you are lucky
you can catch it, modify aa to be an integer to continue, otherwise
your only recourse is to start over again.

So I was wondering if it would be possible to keep that context around
if you are in the debugger and rewind the execution point to before
the statement was triggered. so you could say:

python script.py
(Pdb) c

then hit the exception, say:
(Pdb) aa = 2

then run again
(Pdb) c

to work your way through the exception point. You could then fix the
script inline in an editor.

I can't emphasize exactly how much time and effort this would save. At
best, debugging these types of issues is annoying, at worst it is
excruciating, because they are sometimes intermittent and are not
easily repeatable. Using RemotePdb or Pdb to attach to a long-running
process and having the assurance that the underlying script won't die
because of an inane coding error would do wonders for the reliability
and integrity of scripting.

so - is this possible? just from my experiments it doesn't look so,
but perhaps there is a trick out there that would give this

if it isn't possible, how easy would it be to implement?

Thanks much,