Python debuggers with sys.settrace()

S

Sarah Mount

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?

Many thanks,

Sarah
 
C

Carl Banks

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
 
S

Sarah Mount

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.

Thanks Carl. I had considered this, but it won't catch things like
socket communication. Hmmm.....

Cheers,

Sarah
 
C

Chris Rebert

Thanks Carl. I had considered this, but it won't catch things like
socket communication. Hmmm.....

You could monkeypatch the socket constructors in the `socket` module
to return dummies.

Cheers,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top