jupyter notebook退出网页后不显示输出(已经解决)

问题描述

在jupyter notebook 运行如下代码,此时退出网页端,但不关闭后台jupyter进程。
在这里插入图片描述
10秒后再点进此网页,看不到任何输出。在这里插入图片描述
但是输出a,结果正常,说明此程序在退出网页后没有中断,只是单纯地在关闭网页时没有输出信息。
在这里插入图片描述

这对于跑长任务有很大影响,解决办法如下:
%%capture output
import time
from tqdm import tqdm
for i in tqdm(range(10)):
    print(i)
    time.sleep(1)

在这里插入图片描述
还可以通过右上角的状态来判断,此时程序是否运行完成
此时仍有任务在运行:
此时仍在运行
此时没有任务运行:在这里插入图片描述
这两个状态不受关闭网页的影响,可以完全信任。
我们可以在检查长任务状态时,先查这两个状态,再决定是否输出output。
可惜我搜索全网,还是Jupyter还是没有可以解决不输出的方法,并没有办法看到任务进度情况。
目前最好的解决办法只能在程序中加邮件功能来提示任务进度…


jupyter开发者的回复

https://groups.google.com/g/jupyter/c/8hyGKoBY6O0

MinRK
2015年7月15日 04:29:20
收件人 jup…@googlegroups.com
Since the translation of kernel output message -> output in the notebook document happens in the browser, any outputs that arrive when a browser is not connected are lost. Further, when reopening a notebook with the same browser, not enough information is preserved to resume receiving outputs in the right place. We are working on a different model where more of the notebook state is actually produced on the server, in which case closing your browser will not result in lots output, but we are not there, yet.

I hope that helps,
-MinRK

15年的事了,现在看到他们还没有声明解决了这个问题


倒是看到有个大哥重写了个jupyter,叫CoCal,没有去尝试,估计是可以替代jupyter

Hi,

I implemented “capturing all output even with no browser” for the
CoCalc rewrite of Jupyter. If you try Jupyter notebooks at
https://cocalc.com, or using the cocalc-docker image
(https://github.com/sagemathinc/cocalc-docker), you can see what this
feels like. It works by storing all state on the backend server.

Jason Grout, Chris Colbert, and I talked recently at JupyterCon about
some about plans for JupyterLab (?) to implement functionality like
this, so I think something is in the pipeline. Maybe one of them
wants to comment.

One other workaround is just to send all output to a file by
explicitly using open and write and flush in Python (or whatever
kernel you are using).

– William

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值