• 技术文章 >Python技术 >Python基础教程

    python中pdb的中断控制

    小妮浅浅小妮浅浅2021-10-13 09:39:59原创3464

    1、根据用户输入的调试命令,pdb在跟踪frame的每一步时都会进行中断控制,决定下一步是否中断,中断到哪一行。

    2、stop_here是中断控制的主要方法。

    中断控制是指在输入不同的调试命令后,代码可以执行到正确的位置,等待用户输入。例如,输入s控制台应该在下一个运行frame的代码处停止,输出c需要运行到下一个中断点。在sys.settrace的每一步跟踪中,中断控制是调试运行的核心逻辑。

    实例

    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:当前只要追溯到botframe,就等待执行。
            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的中断控制,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python pdb
    品易云
    上一篇:python中pdb的使用流程 下一篇:python中pdb有哪些调试命令

    相关文章推荐

    • python如何获取最优轮廓系数• python数据类型的使用注意• python导入模块的本质探究• python文件写入和关闭• python中有哪些邮件模块• python邮件协议的介绍• python变量类型的使用• python数据类型转换的注意点• python变量赋值的操作• python copy模块中的函数使用• python中Monkey测试的介绍• python中Monkey测试有什么特点

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网