gpt4 book ai didi

python - 暂停/恢复脚本执行?

转载 作者:太空狗 更新时间:2023-10-30 01:31:33 31 4
gpt4 key购买 nike

我正在尝试找到一种方法来暂停脚本的执行(一个没有超时的方法),这将允许我,例如此时检查变量值,从命令行输入其他命令,然后在我准备好后恢复执行。在 IDL(最近我从 IDL 切换到 Python)中,我能够通过在所选代码行包含“stop”然后键入“.cont”来做到这一点。 Python 中是否存在类似的东西?

非常感谢您的帮助!

(这是我在这里的第一篇文章,所以我希望以上描述符合标准,如果不符合标准,欢迎任何批评意见!)

最佳答案

我相信您正在寻找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.

我建议您从 set_trace() 开始:

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部分。

关于python - 暂停/恢复脚本执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50423272/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com