Debuggers

R. Bernstein rocky at panix.com
Fri Jun 13 07:21:30 EDT 2008


TheSaint <fc14301589 at icqmail.com> writes:

> Hi,
>
> while testing my program I found some strange happening with pdb and pydb.
>
> I like pydb because let me restart the program and nicer features, but if
> errors pop up, then it will forget all variables (globals and locals gone).

I'm not completely sure what you mean, but I gather that in
post-mortem debugging you'd like to inspect local variables defined at the
place of error. For example in this program

  def raise_error:
    x=5
    raise FloatingPointError
  
  raise_error

you'd like to look at x. 

Python as a language is a little different than say Ruby. In Python
the handler for the exception is called *after* the stack is unwound
while in Ruby it is called before. What this means to you is basically
what you reported: that you are not going to be able to see some local
variables after an exception occurs (i.e. in post-mortem debugging)
whether pydb, pdb, any debugger or any Python program you write.

This was mentioned a while back:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/23418f9450c13c2d/b0b1908495dde7bc?lnk=st&q=#b0b1908495dde7bc

By the way, although Ruby *does* call the exception handler before the
stack is unwound, there's no way that I know to *clear* the exception
so that you can dynamically "handle" it. This has a certain legitimacy
since it might be dangerous to continue in some exception and the
state of the interpreter may be inconsistent. For example if I write

  x = 1/0 

or 
  if  1/0 > 5 :

what value do I use for 1/0? (Far worse is where something like a SEGV
occurs, but I'm not sure that will raise an exception instead of
terminate Python.)

> I've to go for pdb because it isn't affected by that problem, but also in
> some case pdb doesn't recognize a fix after a post-mortem restart. The funny
> thing is that it shows the line corrected, but pdb execute the one it put in
> memory.
> However, I think also python shell has such flaw. I'd like to know how to
> blank all current data and restart a program or re-import a corrected class
> sentence.
> Any other to try?
> I'm also prone to use Ipython, but I still miss some learning how to run a
> program within Ipython itself.
> So if I do:
>
> import myprogram
> myprogram.__main__
>
> Will it run? And then the other arguments from CLI, how do I pass them in?
>  --
> Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html



More information about the Python-list mailing list