Python 列出正在运行的 Jupyter 笔记本和令牌

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46551551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:41:43  来源:igfitidea点击:

List running Jupyter notebooks and tokens

pythonsshjupytertmuxgnu-screen

提问by christopherlovell

How do you check the login tokens for all running jupyter notebook instances?

您如何检查所有正在运行的 jupyter notebook 实例的登录令牌?

Example: you have a notebook running in tmuxor screenpermanently, and login in remotely through ssh. Sometimes, particularly if you're logging in after a long time, the token is requested again in order to access the notebook session. How do you get hold of the token without having to kill and restart the notebook session with a new token?

示例:您有一个笔记本正在运行tmuxscreen永久运行,并通过 远程登录ssh。有时,特别是当您在很长时间后登录时,会再次请求令牌以访问笔记本会话。如何在不必使用新令牌终止和重新启动笔记本会话的情况下获取令牌?

回答by christopherlovell

UPDATE

更新

You can now just run jupyter notebook listin the terminal to get the running jupyter sessions with tokens.

您现在可以jupyter notebook list在终端中运行以获取正在运行的带有令牌的 jupyter 会话。

enter image description here

在此处输入图片说明

Take care that you are within the right environment (conda, virtualenv etc.) otherwise the sessions will list without the associated tokens. Eg: The above reference screenshot is from the conda environment.

请注意您处于正确的环境(conda、virtualenv 等)中,否则会话将在没有关联令牌的情况下列出。例如:上面的参考截图来自 conda 环境。

Old answer:

旧答案:

Run ipython and enter the following:

运行 ipython 并输入以下内容:

> ipython
[1] : system("jupyter" "notebook" "list")
Out[1]: 
['Currently running servers:','http://localhost:8895/token=067470c5ddsadc54153ghfjd817d15b5d5f5341e56b0dsad78a :: /u/user/dir']

If the notebook is running on a remote server, you will have to login in to that server first before running ipython.

如果笔记本在远程服务器上运行,则必须先登录到该服务器,然后才能运行 ipython。

回答by pebox11

One easy solution (that can save you time by avoiding opening a new terminal) is from the same terminal you are running the notebookto hit(ONLY ONCE!! - cause twice would kill the running server)

一个简单的解决方案(可通过避免打开一个新的终端节省您的时间)是从正在运行的笔记本电脑相同的终端(仅一次!! -原因两次会杀死正在运行的服务器)

Ctrl + C  

By doing that the full linkto your notebook will appear(along with the token!) and a prompt asking you to confirm shutting down. Just answer no (nand enter) or do nothing and after 5 seconds the operation will resume. In the meanwhile you would have been able to retrieve the link and/or the token you need.

通过这样做,将出现指向您的笔记本的完整链接(以及令牌!)并提示您确认关闭。只需回答 no(n并输入)或什么都不做,5 秒后操作将恢复。同时,您将能够检索所需的链接和/或令牌。

回答by Omisolaidowu Paul

Just right click on the jupyter notebook logo in the currently running server, you probably have a server running already, then click on copy link, then paste the link in a text editor, maybe MS word, you will see the token in the link, copy and paste where token is required. It will work.

只需右键单击当前正在运行的服务器中的 jupyter notebook 徽标,您可能已经有一台服务器正在运行,然后单击复制链接,然后将链接粘贴到文本编辑器中,也许是 MS word,您将在链接中看到令牌,复制并粘贴到需要令牌的地方。它会起作用。

回答by Rhea Thomas

For running python code in jupyter notebook...we need token id which we can obtain from the terminal by just typing jupyter notebookprovided your path has been configured... If not then set your path right first.

为了在 jupyter notebook 中运行 python 代码……我们需要令牌 ID,只要您的路径已配置,我们只需键入jupyter notebook即可从终端获取该 ID ……如果没有,请先设置您的路径。

Sample

样本