Python debuggers with sys.settrace()

  • Follow


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

-- 
Sarah Mount, Senior Lecturer, University of Wolverhampton
website:  http://www.snim2.org/
twitter: @snim2
0
Reply Sarah 5/2/2010 6:06:52 PM

On May 2, 11:06=A0am, Sarah Mount <mount.sa...@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 =3D 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
0
Reply Carl 5/5/2010 9:17:12 AM


On 5 May 2010 10:17, Carl Banks <pavlovevidence@gmail.com> wrote:
> On May 2, 11:06=A0am, Sarah Mount <mount.sa...@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 =3D open(os.devull)"), then
> invoke the debugger with stdout set to sys._stdout (the actual
> stdout). =A0You'll have to create the Pdb() by hand since the built-in
> convience functions don't do it. =A0Check the file pdb.py for details.
>

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

Cheers,

Sarah

--=20
Sarah Mount, Senior Lecturer, University of Wolverhampton
website:  http://www.snim2.org/
twitter: @snim2
0
Reply Sarah 5/6/2010 12:59:04 PM

On Thu, May 6, 2010 at 5:59 AM, Sarah Mount <mount.sarah@gmail.com> wrote:
> On 5 May 2010 10:17, Carl Banks <pavlovevidence@gmail.com> wrote:
>> On May 2, 11:06=C2=A0am, Sarah Mount <mount.sa...@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 =3D open(os.devull)"), then
>> invoke the debugger with stdout set to sys._stdout (the actual
>> stdout). =C2=A0You'll have to create the Pdb() by hand since the built-i=
n
>> convience functions don't do it. =C2=A0Check the file pdb.py for details=
..
>>
>
> 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
--
http://blog.rebertia.com
0
Reply Chris 5/6/2010 1:09:16 PM

3 Replies
127 Views

(page loaded in 0.083 seconds)


Reply: