Mar 25, 2010
Just a little pin prick for your ill pdb
Some packages can compromises the pdb interactive shell by redefining sys.stdout
Disclaimer: Tested only on linux and mac
Symptoms: python readline does not work at all in the pdb shell.
If you find out that inside a pdb after pressing some keys, e.g. the arrow keys, some escape symbols appear on the line...
...and you cannot move the cursor to the desired position, probably some package screwed up your pdb!
This is very annoying to me because some times I have to spend a lot of time in the pdb to heal my buggy code: a misfunctional readline makes me lose too much time!
This probably happened because somewhere in the code the standard output (sys.stdout) has been redefined and this screws up the pdb.
Check it out in the console:
(Pdb) import sys (Pdb) sys.stdout
If the output is not something like
<open file '<stdout>', mode 'w' at 0xb783d070>
than you can go on reading to find out how to fix it.
Don't ask me why pdb does not like it. If you are able to identify the nasty piece of code that modifies the standard output and replicate it in a python console, this problem does not appear.
Therapy: fix the stdout!
In most of the cases this will give you back a fully functional console:
>>> import sys;sys.stdout=file('/dev/stdout','w')