我正在运行在服务器上的IPython笔记本中进行长时间运行的实验,其中典型的工作周期是:启动实验,去吃午餐,回来,检查进度,检查Facebook,检查电子邮件,再次检查Facebook,关闭计算机,回来,检查Facebook,检查进度,...
问题是当我关闭运行笔记本的浏览器窗口时,打印/日志记录输出不再保存在笔记本中.
例如,在我的简单实验中:
import time
start_time = time.time()
for i in xrange(5):
print '%s seconds have passed' % (time.time()-start_time)
time.sleep(2)
print 'Done!'
Run Code Online (Sandbox Code Playgroud)
如果我跑,关闭标签,10秒钟后回来,我只看到笔记本上次保存时的输出.我期望看到的是:
0.000111818313599 seconds have passed
2.00515794754 seconds have passed
4.01105999947 seconds have passed
6.0162498951 seconds have passed
8.01735782623 seconds have passed
Done!
Run Code Online (Sandbox Code Playgroud)
据推测,这将在未来的某个时间点得到修复,但同时在关闭浏览器之后还有一些容易入侵使其继续打印到笔记本输出?奖励点,如果它适用于内嵌图像.
嗯,找到了一个好的解决方案。解决方案位于此文件中: https://github.com/QUVA-Lab/artemis/blob/master/artemis/fileman/persistent_print.py
示例使用: https://github.com/QUVA-Lab/artemis/blob/master/artemis/fileman/test_persistent_print.py
演示现在看起来像:
import time
from general.persistent_print import capture_print, reprint
capture_print()
start_time = time.time()
for i in xrange(5):
print '%s seconds have passed' % (time.time()-start_time)
time.sleep(2)
print 'Done!'
Run Code Online (Sandbox Code Playgroud)
如果我跑
reprint()
Run Code Online (Sandbox Code Playgroud)
在下一个单元格中,它将重新显示自capture_print调用以来所做的所有打印语句。显然,如果没有必要的话会更好,但目前它是有效的。
| 归档时间: |
|
| 查看次数: |
3191 次 |
| 最近记录: |