[英]In pdb (python debugger), can I set a breakpoint on a builtin function?
[英]Is there a way to set a debugger breakpoint on a Python inbuilt function like print()?
我有一個正在使用的大型代碼庫,其中某個地方有一個打印語句,它正在打印許多 '\n' 換行符。
我知道我可以在自己的代碼上設置斷點,但是有沒有辦法設置斷點 Python 的內置 print() 語句? 或者任何內置的 function。
最簡單的方法是什么?
Python 可以在運行時修補,很簡單,所以你可以在運行時的早期添加這樣的東西:
import builtins
orig_print = builtins.print
def my_print(*args, **kwargs):
orig_print(*args, **kwargs)
breakpoint()
builtins.print = my_print
請注意,還有其他方法可以在 stdout/stderr 上獲取字節,例如sys.stdout.write
或logging
stream 處理程序,這不一定是 go 通過print
調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.