问题描述
我让Jupyter在ec2实例的tmux会话中运行.我的单元格运行时间很长,但是当我关闭浏览器或笔记本电脑盖时,笔记本电脑不再写入输出单元格(并且可能使python内核崩溃).
I have Jupyter running in a tmux session on an ec2 instance. I have very long-running cells, but when I close my browser or laptop lid, the notebook no longer writes output cells (and may crash the python kernel).
这是我在远程实例上启动实验的方式:
This is how I launch labs on my remote instance:
jupyter lab --ip=0.0.0.0 --port=5002 --no-browser --allow-root
我正在寻找一种解决方案,可以无限期运行笔记本电脑而不会丢失数据,而不必保持本地计算机的电源.
I'm looking for a solution to run a notebook indefinitely without losing data and without having to keep my local computer on.
- 我不想使用VNC或X-windows转发(太慢)
- 我不想将我的代码重写为python脚本(仅在jupyter实验室中需要工作)
那里必须有一个解决方案!
There has got to be a solution out there!
更新:
以下"nohup"解决方案不起作用:
The 'nohup' solution below doesn't work:
运行此单元格并关闭浏览器后,重新打开后将没有输出:
After running this cell and closing the browser, upon reopening there is no output:
推荐答案
编辑(在澄清之后):
关闭浏览器或笔记本电脑后,您可以使用Jupyter魔术来继续运行单元,然后在返回后打印输出.这是完成的方式:
You can use some Jupyter magic to continue running the cell after you close the browser or laptop, and then print the output after you return. Here's how that's done:
%%capture stored_output
import time
time.sleep(30)
print("Hi")
返回后,运行以下命令:
After returning, run the following:
stored_output.show()
# Hi
原始:
您需要使用nohup启动笔记本电脑.
You need to launch the notebook with nohup.
nohup jupyter notebook &
添加&"只需要返回外壳.笔记本将在后台运行,并且在关闭SSH连接时不会杀死其进程ID.
Adding the '&' is only needed to return the shell. The notebook will be running in the background and it's process ID won't be killed when you close your SSH connection.
这篇关于长时间运行的Jupyter笔记本/实验室?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!