我想尽可能详细地报告我的笔记本的执行情况。简而言之,我想实时查看我的笔记本正在执行的每个操作。例如,我的一个函数有一个 sleep 周期为 5 秒的循环,我希望看到程序实际上正在 sleep 并且循环的其他步骤正在执行。
我一直在努力寻找如何做到这一点,我只能找到获得需要触发错误的事后调试报告的方法。
最佳答案
您可能需要考虑 trace
模块,它有一个编程接口(interface)。
例子:
import sys
import trace
# create a Trace object, telling it what to ignore, and whether to
# do tracing or line-counting or both.
tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=0,
count=1
)
# run the new command using the given tracer
tracer.run('main()')
# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True, coverdir=".")
想到的其他选项是 tqdm
(简单的进度条),或this answer 中列出的内容.
关于python - 获取笔记本的详细实时报告/监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66650617/