问题描述
在jupyter notebook 运行如下代码,此时退出网页端,但不关闭后台jupyter进程。
10秒后再点进此网页,看不到任何输出。
但是输出a,结果正常,说明此程序在退出网页后没有中断,只是单纯地在关闭网页时没有输出信息。
这对于跑长任务有很大影响,解决办法如下:
%%capture outputimport timefrom tqdm import tqdmfor i in tqdm(range(10)):print(i)time.sleep(1)
还可以通过右上角的状态来判断,此时程序是否运行完成
此时仍有任务在运行:
此时没有任务运行:
这两个状态不受关闭网页的影响,可以完全信任。
我们可以在检查长任务状态时,先查这两个状态,再决定是否输出output。
可惜我搜索全网,还是Jupyter还是没有可以解决不输出的方法,并没有办法看到任务进度情况。
目前最好的解决办法只能在程序中加邮件功能来提示任务进度…
jupyter开发者的回复
/g/jupyter/c/8hyGKoBY6O0
MinRK
7月15日 04:29:20
收件人 jup…@
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
的事了,现在看到他们还没有声明解决了这个问题
倒是看到有个大哥重写了个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
, or using the cocalc-docker image
(/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