- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
基本上,标题。
我正试图追踪在大型代码库中发生虚假打印的位置,并且我想在打印“发生”时中断或以某种方式获取堆栈跟踪。有什么想法吗?
最佳答案
对于这种特殊情况,您可以将 stdout
重定向到打印输出及其调用者的辅助类。您也可以打破其中一种方法。
完整示例:
import sys
import inspect
class PrintSnooper:
def __init__(self, stdout):
self.stdout = stdout
def caller(self):
return inspect.stack()[2][3]
def write(self, s):
self.stdout.write("printed by %s: " % self.caller())
self.stdout.write(s)
self.stdout.write("\n")
def test():
print 'hello from test'
def main():
# redirect stdout to a helper class.
sys.stdout = PrintSnooper(sys.stdout)
print 'hello from main'
test()
if __name__ == '__main__':
main()
输出:
printed by main: hello from main
printed by main:
printed by test: hello from test
printed by test:
如果您需要更全面的信息,您也可以只打印 inspect.stack()
。
关于python - 是否有破解 pdb 内置打印的技巧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10742501/
我正在启动一个 web api 项目,当我尝试在逻辑层(这是一个单独的 csproj)中设置断点时我注意到了这个问题,它显示了未经验证的断点。 深入研究后,我发现调试控制台显示“无法找到或打开 PDB
我已经下载了 FreeImage 源代码并自己为 X64 MT DLL 进行了静态构建。 一切正常,除了当我在 freeimage.lib 文件中使用链接时,我收到很多烦人的链接器警告,我不太了解原因
Ubuntu 16.04 Python 3.5.2 如果我运行 python,在 virtualenv 中,我会得到 Python 3.5.2。 问题是: (photoarchive) admin@s
在 pdb 模式下,我经常想单步执行一个函数。这是一个说明我可能会做什么的情况。给定代码: def f(x): print('doing important stuff..') res
我有父进程调用它的子进程。我把 import pdb; pdb.set_trace() 进入子进程代码。 当我使用 python -m pdb parent.py 启动父级时,它被卡住了。调试器不响应
这个问题在这里已经有了答案: Cannot find or open the PDB file in Visual Studio C++ 2010 (7 个答案) 关闭 8 年前。 我正在使用最近升
我对 python 和 pdb 比较陌生,但我对 gdb 有很多经验。 我的问题是,如果我在某个时候在我的代码中设置了一些断点,我将想要更改某些内容并重新运行我的调试 session ,同时保留这些断
我对编译器和链接器 PDB 文件分别有什么区别感到困惑(即在 Visual Studio 中,Project Properties > C/C++ > Output Files >程序数据库文件名 v
我有一个 PDB 文件列表。我想使用 BioPython 中的 Bio.PDB 模块提取所有文件的配体(因此,杂原子)并将每个单独保存到 PDB 文件中。 我尝试了一些解决方案,例如:Remove h
尝试使用 pdb 调试我的基于 python 的 roguelike。我想弄清楚的是,函数handle_keys()是否像我所问的那样返回0。我有另一个函数没有按预期运行,所以我试图找出问题发生的地方
我有私有(private) pdb 文件,我必须将其转换为公共(public)文件。有工具吗? 最佳答案 使用PDBCopy . pdbcopy 是 Windows 调试工具的一部分,可通过 Wind
在静态编译的链接阶段在 Windows 上构建时可能会出现 LNK4099 警告。 例如使用 nmake 和 VC10 进行构建时,我收到一连串 LNK4099 警告,例如: libcurl_a_de
我的 Visual Studio 2013 ASP.NET webform 应用程序有 3 个 DLL 程序集。调试时,DLL 和 PDB 仅在三个 DLL 中的两个(项目/VB 模块和一个 C# 模
我有一个 Python 程序,里面有一个函数 foo()。 我使用 PDB 运行程序,并在程序中某处的任意断点处停止。 现在,我可以很容易地从 PDB 中调用 foo(),我只需键入: !foo()
我正在尝试使用 this tutorial 学习 pdb引用自 another stackoverflow question ,我正处于“入门”部分的第 3 步。 In [12]: %paste #
我有 DLL,并且有用于创建 DLL 的确切源代码。当我们从客户那里获得转储文件时,我希望我们的本地符号服务器能够工作。 (在我们产品的下一个补丁/版本之前无法在客户站点更新 DLL) 最佳答案 这似
这个问题可能真的很愚蠢,但就是这样。以下语句触发特定电子邮件的异常: File "/Users/me/tools/maildir-deduplicate/maildir_deduplicate/m
在从我的旧 XP 移动到新的 vista PC 后,我在 VS2005 中的一个旧项目中收到以下几个警告: UnitTest++.vsnet2005.lib(TestRunner.obj) : 警告
我正在尝试使用 Visual Studio 编译 Qt 4.8.6 项目(我使用的是用于 Qt4.8.6 的 visual studio 插件)。我在调试和 Release模式 (-debug-and
我想用ipdb而不是 pdb与 py.test --pdb选项。这可能吗?如果是这样,如何? 显然,我可以使用 import ipdb; ipdb.set_trace()在代码中但需要运行测试,观察它
我是一名优秀的程序员,十分优秀!