IPython Notebook-关闭浏览器后继续打印到笔记本输出 [英] IPython Notebook - Keep printing to notebook output after closing browser

查看:112
本文介绍了IPython Notebook-关闭浏览器后继续打印到笔记本输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在服务器上运行的IPython笔记本中进行长时间运行的实验,典型的工作周期是:启动实验,吃午饭,回来,检查进度,检查Facebook,检查电子邮件,再次检查Facebook,关闭计算机,回来,检查Facebook,检查进度,...

I'm doing long-running experiments in an IPython notebook running on a server, where the typical work cycle is: launch experiment, go to lunch, come back, check progress, check Facebook, check email, check Facebook again, turn off computer, come back, check Facebook, check progress, ...

问题是,当我关闭运行笔记本电脑的浏览器窗口时,打印/记录输出不再保存在笔记本电脑中.

The problem is that when I close the browser window where the notebook is running, the print/logging outputs are no longer saved in the notebook.

例如,在我的简单实验中:

For instance, in my simple experiment:

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!'

如果我跑步,请关闭选项卡,然后在10秒钟后返回,我只会看到上次保存笔记本时的输出.我希望看到的是:

If I run, close the tab, and come back 10 seconds later, I just see whatever the output was when the notebook was last saved. What I expect to see is:

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!

大概这将在将来的某个时间解决,但是与此同时,是否有一些简单的技巧可以使它在关闭浏览器后继续打印到笔记本输出?奖励积分(如果适用于嵌入式图像).

Presumably this will be fixed at some point in the future, but in the mean time is there some easy hack to make it continue printing to notebook output after closing the browser? Bonus points if it works for inline images.

推荐答案

好,找到了一个好的解决方案.解决方案在此文件中: https://github.com/QUVA-Lab/artemis /blob/master/artemis/fileman/persistent_print.py

Well, found an ok solution. Solution is in this file: 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!'

如果我跑步

reprint()

在下一个单元格中,它将重新显示自capture_print被调用以来所做的所有打印语句.显然,如果不需要这样做会更好,但是现在可以使用.

In the next cell, it will redisplay all the print statements made since capture_print was called. Obviously it would be better if this were unnecessary, but it works for now.

这篇关于IPython Notebook-关闭浏览器后继续打印到笔记本输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆