暂停/恢复脚本执行?

2024-06-06 12:06:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图找到一种暂停脚本执行(不是超时)的方法,允许我在该点检查变量值,从命令行输入其他命令,然后在准备好后恢复执行。在IDL中(我最近刚从IDL切换到Python),我可以通过在所选代码行中包含“stop”,然后键入“.cont”来做到这一点。Python中是否存在类似的东西?你知道吗

非常感谢您的帮助!你知道吗

(这是我在这里的第一篇文章,所以我希望上述描述符合标准,但如果不符合,我欢迎任何批评反馈!)你知道吗


Tags: 方法代码命令行命令脚本键入文章idl
1条回答
网友
1楼 · 发布于 2024-06-06 12:06:21

我相信你在找the Python Debugger (pdb)

The module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame. It also supports post-mortem debugging and can be called under program control.

我建议你从^{}开始:

The typical usage to break into the debugger from a running program is to insert

import pdb; pdb.set_trace()

at the location you want to break into the debugger. You can then step through the code following this statement, and continue running without the debugger using the continue command.

一定要看一下the other ways to enter the DebuggerDebugger Commands部分。你知道吗

相关问题 更多 >