【发布时间】:2021-03-16 07:23:03
【问题描述】:
我希望尽可能详细地报告我的笔记本的执行情况。简而言之,我想实时查看我的笔记本正在执行的每个操作。例如,我的一个函数有一个睡眠周期为 5 秒的循环,我想看看程序实际上正在睡眠,并且循环的其他步骤正在执行。
我一直在努力寻找如何做到这一点,我只能找到获得需要触发错误的事后调试报告的方法。
【问题讨论】:
标签: python jupyter-notebook reporting
我希望尽可能详细地报告我的笔记本的执行情况。简而言之,我想实时查看我的笔记本正在执行的每个操作。例如,我的一个函数有一个睡眠周期为 5 秒的循环,我想看看程序实际上正在睡眠,并且循环的其他步骤正在执行。
我一直在努力寻找如何做到这一点,我只能找到获得需要触发错误的事后调试报告的方法。
【问题讨论】:
标签: python jupyter-notebook reporting
您可能需要考虑trace 模块,它有一个编程接口。
例子:
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 中列出的内容。
【讨论】: