Python 无法退出正在运行的 jupyter notebook 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38511673/
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 21:04:19  来源:igfitidea点击:

cannot quit jupyter notebook server running

pythonserverjupyterjupyter-notebook

提问by Joalito

I am using Jupyter Notebook for a project. Since I ssh into a linux cluster at work I use

我正在为一个项目使用 Jupyter Notebook。因为我在工作时通过 ssh 进入一个 linux 集群,所以我使用

ssh -Y -L 8000:localhost:8888 user@host

Then I start the notebook with jupyter notebook --no-browser &so that I can continue using the terminal. Then on my local machine I open to localhost:8000and go about my work.

然后我启动笔记本,jupyter notebook --no-browser &以便我可以继续使用终端。然后在我的本地机器上打开localhost:8000并开始我的工作。

My problem is that I forgot several times to close the server by foregrounding the process and killing it with Ctrl-C. Instead I just logged out of the ssh session. Now when I run jupyter notebook listI get

我的问题是我多次忘记通过将进程置于前台并使用Ctrl-C. 相反,我只是退出了 ssh 会话。现在,当我跑步时,jupyter notebook list我得到

Currently running servers:
http://localhost:8934/ :: /export/home/jbalsells
http://localhost:8870/ :: /export/home/jbalsells
http://localhost:8892/ :: /export/home/jbalsells
http://localhost:8891/ :: /export/home/jbalsells
http://localhost:8890/ :: /export/home/jbalsells
http://localhost:8889/ :: /export/home/jbalsells
http://localhost:8888/ :: /export/home/jbalsells

I obviously do not want all of these servers running on my work's machine, but I do not know how to close them!

我显然不希望所有这些服务器都在我工作的机器上运行,但我不知道如何关闭它们!

When I run ps I get nothing:

当我运行 ps 时,我什么也没得到:

  PID TTY          TIME CMD
12678 pts/13   00:00:00 bash
22584 pts/13   00:00:00 ps

I have Jupyter 4.1.0 installed.

我安装了 Jupyter 4.1.0。

回答by Joalito

So I found a solution.

所以我找到了一个解决方案。

Since jupyter notebook listtells you which ports the notebook servers are running on I looked for the PIDs using netstat -tulpnI got the information from http://www.cyberciti.biz/faq/what-process-has-open-linux-port/

由于jupyter notebook list告诉您笔记本服务器在哪些端口上运行,我使用netstat -tulpnhttp://www.cyberciti.biz/faq/what-process-has-open-linux-port/获得的信息查找了 PID

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
PID/Program name    
tcp        0      0 0.0.0.0:8649            0.0.0.0:*               LISTEN      
-                   
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      
-                   
tcp        0      0 0.0.0.0:33483           0.0.0.0:*               LISTEN      
-                   
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      
39125/Xvnc          

Without looking too hard I was able to find the ports I knew to look for from jupyter notebook listand the processes running them (you could use grepif it were too hard to find them). Then I killed them with kill 8337(or whatever number was associated).

不用费力寻找,我就能找到我知道要查找的端口jupyter notebook list以及运行它们的进程(grep如果很难找到它们,您可以使用它们)。然后我用kill 8337(或任何关联的数字)杀死了它们 。

回答by Hongsoog

Windows Systems commands on Command Prompt

命令提示符上的 Windows 系统命令

Be careful to save all the changes made in your notebooks prior to kill the jupyter notebook server process.

在终止 jupyter notebook 服务器进程之前,请小心保存在 notebook 中所做的所有更改。

i) find the port number used by jupyter notebook server

i) 找到 jupyter notebook 服务器使用的端口号

jupyter notebook list

ex.)

前任。)

jupyter notebook list
Currently running servers:
http://127.0.0.1:8888/ :: D:\kimkk\Documents\JupyterNotebook

ii) find process ids that use the found port number of jupyter notebook

ii) 查找使用找到的 jupyter notebook 端口号的进程 ID

netstat -ano | find "found portnumber"

ex.)

前任。)

netstat -ano | find "8888"

  TCP    127.0.0.1:8888         0.0.0.0:0              LISTENING       24140
  TCP    127.0.0.1:8888         127.0.0.1:55588        ESTABLISHED     24140
  TCP    127.0.0.1:8888         127.0.0.1:55612        ESTABLISHED     24140
  TCP    127.0.0.1:55588        127.0.0.1:8888         ESTABLISHED     6492
  TCP    127.0.0.1:55612        127.0.0.1:8888         ESTABLISHED     6492
  • find rows with second column value equals to "8888". In above example first, second, and third rows are target rows. In those rows, you can find PID in the last column (ex. 24140).
  • 查找第二列值等于“8888”的行。在上面的例子中,第一行、第二行和第三行是目标行。在这些行中,您可以在最后一列中找到 PID(例如 24140)。

iii) kill jupyter notebook process with found PID

iii) 使用找到的 PID 杀死 jupyter notebook 进程

taskkill /PID found_PID /F

ex.)

前任。)

taskkill /PID 24140 /F
  • /F means forcely kill the process.
  • /F 表示强行杀死进程。

FYI, Jupyter notebook from version 5.1 supports stop command as follows:

仅供参考,Jupyter notebook 5.1 版支持如下停止命令:

jupyter notebook stop 8888

refer to https://github.com/jupyter/notebook/issues/1950

参考https://github.com/jupyter/notebook/issues/1950

回答by smsarwar

Use the following command to stop Jupyter notebook running on port 8888:

使用以下命令停止在端口 8888 上运行的 Jupyter notebook:

fuser -k 8888/tcp 

回答by ShusenTang

This might help:

这可能有帮助:

  1. run jupyter notebook listto get the port number jupyter uses.
  2. run lsof -n -i4TCP:[port-number]to get PID. The PID is the second field in the output.
  3. run kill -9 [PID]to kill this process.
  1. 运行jupyter notebook list以获取 jupyter 使用的端口号。
  2. 运行lsof -n -i4TCP:[port-number]以获取PID。PID 是输出中的第二个字段。
  3. 运行kill -9 [PID]以终止此进程。

回答by pramithus

I ran into the same issue and followed the solution posted above. Just wanted to clearify the solution a little bit.

我遇到了同样的问题并遵循了上面发布的解决方案。只是想稍微澄清一下解决方案。

netstat -tulpn

will list all the active connections.

将列出所有活动连接。

tcp    0   0 0.0.0.0:8888  0.0.0.0:*  LISTEN      19524/python

you will need the PID "19524" in this case. you can even use the following to get the PID of the port you are trying to shut down

在这种情况下,您将需要 PID“19524”。您甚至可以使用以下命令来获取您尝试关闭的端口的 PID

fuser 8888/tcp

this will give you 19524 as well.

这也会给你 19524。

kill 19524

will shut down the port

将关闭端口

回答by Ceddrick

Section 3.3 should be applicable to this. http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html

第 3.3 节应适用于此。 http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html

When a notebook is opened, its “computational engine” (called the kernel) is automatically started. Closing the notebook browser tab, will not shut down the kernel, instead the kernel will keep running until is explicitly shut down.

To shut down a kernel, go to the associated notebook and click on menu File -> Close and Halt. Alternatively, the Notebook Dashboard has a tab named Running that shows all the running notebooks (i.e. kernels) and allows shutting them down (by clicking on a Shutdown button).

当笔记本打开时,它的“计算引擎”(称为内核)会自动启动。关闭笔记本浏览器选项卡不会关闭内核,而是内核将继续运行,直到被明确关闭。

要关闭内核,请转到关联的笔记本并单击菜单 File -> Close and Halt。或者,Notebook Dashboard 有一个名为 Running 的选项卡,显示所有正在运行的 notebook(即内核)并允许关闭它们(通过单击 Shutdown 按钮)。

回答by tariksalay

On your notebook the welcoming page is named "Files" and you can see "Running" next to it. There is where you would want to shutdown and see the running notebooks

在你的笔记本上,欢迎页面被命名为“文件”,你可以在它旁边看到“正在运行”。您可以在此处关闭并查看正在运行的笔记本