Python debuggers with sys.settrace()

Carl Banks pavlovevidence at gmail.com
Wed May 5 05:17:12 EDT 2010


On May 2, 11:06 am, Sarah Mount <mount.sa... at gmail.com> wrote:
> This is a bit of an odd question, but is there any way for a Python
> debugger to suppress I/O generated by the program which is being
> debugged? I guess an "obvious" thing to do would be to replace core
> parts of the standard library and change any relevant imports in the
> locals and globals dicts to fake ones which don't generate I/O, but
> this seems brittle as the standard library will change over time. Is
> it possible to modify the byte-compiled code in each stack frame? Or
> is there a simpler way to do this?

It's not foolproof but you could try to reassign sys.stdout and
sys.stderr to a bit bucket ("sys.stdout = open(os.devull)"), then
invoke the debugger with stdout set to sys._stdout (the actual
stdout).  You'll have to create the Pdb() by hand since the built-in
convience functions don't do it.  Check the file pdb.py for details.


Carl Banks



More information about the Python-list mailing list