新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:python中pdb的中斷控制
1、根據(jù)用戶輸入的調(diào)試命令,pdb在跟蹤frame的每一步時(shí)都會(huì)進(jìn)行中斷控制,決定下一步是否中斷,中斷到哪一行。

2、stop_here是中斷控制的主要方法。
中斷控制是指在輸入不同的調(diào)試命令后,代碼可以執(zhí)行到正確的位置,等待用戶輸入。例如,輸入s控制臺(tái)應(yīng)該在下一個(gè)運(yùn)行frame的代碼處停止,輸出c需要運(yùn)行到下一個(gè)中斷點(diǎn)。在sys.settrace的每一步跟蹤中,中斷控制是調(diào)試運(yùn)行的核心邏輯。
實(shí)例
def stop_here(self, frame):
# (CT) stopframe may now also be None, see dispatch_call.
# (CT) the former test for None is therefore removed from here.
if self.skip and \
self.is_skipped_module(frame.f_globals.get('__name__')):
return False
# next
if frame is self.stopframe:
# stoplineno >= 0 means: stop at line >= the stoplineno
# stoplineno -1 means: don't stop at all
if self.stoplineno == -1:
return False
return frame.f_lineno >= self.stoplineno
# step:當(dāng)前只要追溯到botframe,就等待執(zhí)行。
while frame is not None and frame is not self.stopframe:
if frame is self.botframe:
return True
frame = frame.f_back
return False以上就是python中pdb的中斷控制,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
當(dāng)前標(biāo)題:創(chuàng)新互聯(lián)Python教程:python中pdb的中斷控制
標(biāo)題路徑:http://m.fisionsoft.com.cn/article/dpjiejc.html


咨詢
建站咨詢
