views:

65

answers:

2

I love python and hate the pdb debugger.

For instance, if I have a program where stdout is redirected, my pdb prompts all go to the redirection, because the library was written to write to stdout.

Oftentimes this problem is subtle, causing me to think a program is hanging when it's really waiting for input.

How do people work around this? (Unfortunately, using other debuggers like winpdb is not an option).

Thanks, /YGA

+1  A: 

If you are invoking pdb in code, you can pass your own stdout into the constructor. sys.__stdout__ might be a good choice.

If you are invoking pdb from the command line, you could copy the main() function from pdb.py into your own sane_pdb.py. Then change the Pdb() initialization to:

pdb = Pdb(stdout=sys.__stdout__)

Then you can invoke sane_pdb.py instead of pdb.py. It's not awesome that you'd have to copy 40 lines into your own file just to change one of them, but it's an option.

Ned Batchelder
+1  A: 

This answer is just to supplement Ned's, as a way of wrapping the pdb.py main() function in a manner which doesn't require copying 40 lines just to change one of them:

# sane_pdb.py: launch Pdb with stdout on original
import sys, pdb
def fixed_pdb(Pdb=pdb.Pdb):
    '''make Pdb() tied to original stdout'''
    return Pdb(stdout=sys.__stdout__)

if __name__ == '__main__':
    pdb.Pdb = fixed_pdb
    pdb.main()

I don't know if it actually works for the questioner's problem, but it does what Ned described...

Peter Hansen