Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Python pdb.set_trace()与重新分配的sys.stdout一起使用?_Python_Pdb - Fatal编程技术网

如何将Python pdb.set_trace()与重新分配的sys.stdout一起使用?

如何将Python pdb.set_trace()与重新分配的sys.stdout一起使用?,python,pdb,Python,Pdb,我希望通过命令过滤Python脚本的输出,同时能够正常使用pdb.set_trace 我运行以下脚本: #!/usr/bin/python import sys, os, pdb print "first line" sys.stdout = os.popen('./filter', 'w') #pdb.set_trace() print "second line" print "third line" 过滤器脚本如下所示: #!/usr/bin/python import subp

我希望通过命令过滤Python脚本的输出,同时能够正常使用pdb.set_trace

我运行以下脚本:

#!/usr/bin/python

import sys, os, pdb

print "first line"
sys.stdout = os.popen('./filter', 'w')
#pdb.set_trace()
print "second line"
print "third line"  
过滤器脚本如下所示:

#!/usr/bin/python

import subprocess, sys

subprocess.call( 'cat', stdout=sys.stdout, stderr=sys.stderr, shell=True )
一切正常,我在终端上看到了输出。但是,当我取消对set_跟踪行的注释时,调试器显然中断了,我可以使用命令,但直到整个程序存在,我才看到它们的输出,所以交互式调试中断了


如何更改筛选器以使交互式调试工作?

您可以尝试创建自己的Pdb实例。例如

mypdb = pdb.Pdb(stdout=sys.__stdout__)

您可以尝试创建自己的Pdb实例。例如

mypdb = pdb.Pdb(stdout=sys.__stdout__)

谢谢你,但我不能那样做。我无法更改脚本或要求用户使用mypdb。我只能换个过滤器,那你就是索尔了。您不能从子进程取消重定向stdout。谢谢,但我不能这样做。我无法更改脚本或要求用户使用mypdb。我只能换个过滤器,那你就是索尔了。无法从子进程取消重定向标准输出。