问题:如何正确关闭IPython Notebook?

如何正确关闭IPython Notebook?

目前,我只是关闭浏览器选项卡,然后Ctrl+C在终端中使用。
不幸的是,exit()滴答和滴答都Kill kernel upon exit没有帮助(它们确实杀死了它们的内核,但是没有退出iPython)。

How to close IPython Notebook properly?

Currently, I just close the browser tabs and then use Ctrl+C in the terminal.
Unfortunately, neither exit() nor ticking Kill kernel upon exit does help (they do kill the kernel they but don’t exit the iPython).


回答 0

当前没有比终端中的Ctrl + C更好的方法了。

我们正在考虑如何进行显式关机,但是笔记本作为单用户应用程序(用户可以自由停止它)和作为多用户服务器(只能由管理员使用)之间存在一定的压力。阻止它。我们还没有弄清楚如何处理差异。

(对于将来的读者来说,就是0.12已发布而0.13正在开发中的情况。)

2017年12月更新

IPython Notebook已成为Jupyter Notebook。最新版本添加了jupyter notebook stopshell命令,该命令将关闭在该系统上运行的服务器。如果不是默认端口8888,则可以在命令行中传递端口号。

您还可以使用nbmanager,它是一个桌面应用程序,可以显示正在运行的服务器并关闭它们。

最后,我们正在努力添加:

  • 一个配置选项,如果您在指定时间内不使用服务器,则会自动关闭服务器。
  • 用户界面中的一个按钮,用于关闭服务器。(我们知道花了这么长时间真是太疯狂了。更改UI引发了争议。)

There isn’t currently a better way to do it than Ctrl+C in the terminal.

We’re thinking about how to have an explicit shutdown, but there’s some tension between the notebook as a single-user application, where the user is free to stop it, and as a multi-user server, where only an admin should be able to stop it. We haven’t quite worked out how to handle the differences yet.

(For future readers, this is the situation with 0.12 released and 0.13 in development.)

Update December 2017

The IPython Notebook has become the Jupyter Notebook. A recent version has added a jupyter notebook stop shell command which will shut down a server running on that system. You can pass the port number at the command line if it’s not the default port 8888.

You can also use nbmanager, a desktop application which can show running servers and shut them down.

Finally, we are working on adding:

  • A config option to automatically shut down the server if you don’t use it for a specified time.
  • A button in the user interface to shut the server down. (We know it’s a bit crazy that it has taken this long. Changing UI is controversial.)

回答 1

如果您像我一样在后台运行jupyter:

jupyter notebook &> /dev/null &

然后要完全退出jupyter,而不是Ctl-C,请使用别名命令:

echo 'alias quitjupyter="kill $(pgrep jupyter)"' >> ~/.bashrc

重新启动终端。杀死所有jupyter实例:

quitjupyter

注意:如上所示,在单引号内使用双引号。另一种方法是在将表达式写入您的.bashrc之前先对表达式求值(您要编写的命令本身不是’kill 1430’或可能与当前jupyter实例相关的任何进程号)。当然,您可以使用任何所需的别名。我实际上使用’qjup’:

echo 'alias qjup="kill $(pgrep jupyter)"' >> ~/.bashrc

重新启动终端。杀死所有jupyter实例:

qjup

If you run jupyter in the background like me:

jupyter notebook &> /dev/null &

Then to exit jupyter completely, instead of Ctl-C, make an alias command:

echo 'alias quitjupyter="kill $(pgrep jupyter)"' >> ~/.bashrc

Restart your terminal. Kill all jupyter instances:

quitjupyter

Note: use double quotes inside of single quotes as shown above. The other way around will evaluate the expression before writing it to your .bashrc (you want to write the command itself not ‘kill 1430’ or whatever process number may be associated with a current jupyter instance). Of course you can use any alias you wish. I actually use ‘qjup’:

echo 'alias qjup="kill $(pgrep jupyter)"' >> ~/.bashrc

Restart your terminal. Kill all jupyter instances:

qjup

回答 2

我认为已接受的答案已过时,不再有效。

您可以从文件菜单项上的Web界面终止Jupyter Notebook。

在此处输入图片说明

将鼠标光标移至“关闭并停止”位置时,将看到以下说明。

在此处输入图片说明

当您单击“关闭并停止”时,您将在终端屏幕上看到以下消息。

在此处输入图片说明

I think accepted answer outdated and is not valid anymore.

You can terminate jupyter notebook from web interface on file menü item.

enter image description here

When you move Mouse cursor on “close and halt”, you will see following explanation.

enter image description here

And when you click “close and halt”, you will see following message on terminal screen.

enter image description here


回答 3

第一步是保存所有打开的笔记本。然后考虑关闭正在运行的Jupyter Notebook。您可以使用以下简单命令:

$ jupyter notebook stop 
Shutting down server on port 8888 ...

它也将端口号作为参数,您可以正常关闭jupyter笔记本。

例如:

jupyter notebook stop 8889 
Shutting down server on port 8889 ...

此外,要了解您当前的juypter实例正在运行,请检查以下命令:

shell> juypter notebook list 
Currently running servers:
http://localhost:8888/?token=ef12021898c435f865ec706d7c9af8607a7ba58bbee98632 :: /Users/username/jupyter-notebooks [/code]

First step is to save all open notebooks. And then think about shutting down your running Jupyter Notebook. You can use this simple command:

$ jupyter notebook stop 
Shutting down server on port 8888 ...

Which also takes the port number as argument and you can shut down the jupyter notebook gracefully.

For eg:

jupyter notebook stop 8889 
Shutting down server on port 8889 ...

Additionally to know your current juypter instance running, check below command:

shell> juypter notebook list 
Currently running servers:
http://localhost:8888/?token=ef12021898c435f865ec706d7c9af8607a7ba58bbee98632 :: /Users/username/jupyter-notebooks [/code]

回答 4

这些命令对我有用:

jupyter notebook list # shows the running notebooks and their port-numbers
                      # (for instance: 8080)
lsof -n -i4TCP:[port-number] # shows PID.
kill -9 [PID] # kill the process.

这个答案改编自这里

These commands worked for me:

jupyter notebook list # shows the running notebooks and their port-numbers
                      # (for instance: 8080)
lsof -n -i4TCP:[port-number] # shows PID.
kill -9 [PID] # kill the process.

This answer was adapted from here.


回答 5

如果没有其他作用,请尝试从任务管理器(如果是Windows)中终止pythonw进程。

Try killing the pythonw process from the Task Manager (if Windows) if nothing else works.


回答 6

Linux (Ubuntu 14.04)

如前所述,尝试通过先转到ipynb / jupyter浏览器会话中的“运行”选项卡来正确终止ipython Notebook进程,然后检查控制台上打开的终端并使用ctrl-c关闭。如果可能,应避免后者。

如果您运行,ipython notebook list并继续看到在不同端口上运行ipython服务器,请记下现有笔记本计算机将服务于哪些端口。然后关闭您的TCP端口:

fuser -k 'port#'/tcp 

我不确定这样做是否还会涉及其他风险。如果是这样,请告诉我。

Linux (Ubuntu 14.04)

As mentioned, try to kill ipython notebook processes properly by first going to the “running” tab in your ipynb/jupyter browser session, and then check open terminals on your console and shut down with ctrl-c. The latter should be avoided if possible.

If you run an ipython notebook list and continue to see running ipython servers at different ports, make note of which ports the existing notebooks are being served to. Then shut down your TCP ports:

fuser -k 'port#'/tcp 

I’m not sure if there are other risks involved with doing this. If so, let me know.


回答 7

环境


我的操作系统是Ubuntu 16.04,jupyter是4.3.0。

方法


首先,我在浏览器的主页上注销了jupyter(注销按钮在右上角)

第二,输入Ctrl + C您的终端,它显示:

[I 15:59:48.407 NotebookApp]从本地目录中断服务笔记本:/ home / Username 0活动内核

Jupyter Notebook在以下位置运行: http:// localhost:8888 /?token = a572c743dfb73eee28538f9a181bf4d9ad412b19fbb96c82

关闭此笔记本服务器(y / [n])?

最后一步,y在5秒钟内键入,如果显示:

[C 15:59:50.407 NotebookApp]已确认关闭
[I 15:59:50.408 NotebookApp]正在关闭内核

恭喜!您成功关闭了jupyter。

Environment


My OS is Ubuntu 16.04 and jupyter is 4.3.0.

Method


First, i logged out jupyter at its homepage on browser(the logout button is at top-right)

Second, type in Ctrl + C in your terminal and it shows:

[I 15:59:48.407 NotebookApp]interrupted Serving notebooks from local directory: /home/Username 0 active kernels

The Jupyter Notebook is running at: http://localhost:8888/?token=a572c743dfb73eee28538f9a181bf4d9ad412b19fbb96c82

Shutdown this notebook server (y/[n])?

Last step, type in y within 5 sec, and if it shows:

[C 15:59:50.407 NotebookApp] Shutdown confirmed
[I 15:59:50.408 NotebookApp] Shutting down kernels

Congrats! You close your jupyter successfully.


回答 8

实际上,我相信有一种比使用kill或task manager杀死进程更干净的方法。

在Jupyter Notebook仪表板(首次启动“ Jupyter Notebook”时会看到的浏览器界面)中,浏览到浏览器中已关闭但其内核可能仍在运行的笔记本文件的位置。

iPython Notebook文件带有书本图标,如果它具有正在运行的内核,则显示为绿色,如果内核未运行,则显示为灰色。

只需选中正在运行的文件旁边的复选框,然后单击出现在文件上方的“关机”按钮即可。

这将正确关闭与该特定笔记本电脑关联的内核。

Actually, I believe there’s a cleaner way than killing the process(es) using kill or task manager.

In the Jupyter Notebook Dashboard (the browser interface you see when you first launch ‘jupyter notebook’), browse to the location of notebook files you have closed in the browser, but whose kernels may still be running.

iPython Notebook files appear with a book icon, shown in green if it has a running kernel, or gray if the kernel is not running.

Just select the tick box next to the running file, then click on the Shutdown button that appears above it.

This will properly shut down the kernel associated with that specific notebook.


回答 9

在浏览器会话中,您也可以转到Kernel,然后单击Restart and Clear Output

In the browser session you can also go to Kernel and then click Restart and Clear Output.


回答 10

我复制从Jupyter / IPython的笔记本电脑快速入门指南文档粘贴,发布了2月13日,2018年 http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html

1.3.3关闭笔记本:内核关闭打开笔记本时,将自动启动其“计算引擎”(称为内核)。关闭笔记本浏览器选项卡将不会关闭内核,而是内核将一直运行直到被明确关闭。要关闭内核,请转到关联的笔记本,然后单击菜单文件->关闭并暂停。另外,笔记本仪表板有一个名为“运行”的选项卡,其中显示了所有正在运行的笔记本(即内核),并允许将其关闭(通过单击“关机”按钮)。

摘要:首先关闭并停止笔记本计算机的运行。

1.3.2关闭Jupyter Notebook应用程序关闭浏览器(或选项卡)将不会关闭Jupyter Notebook应用程序。要完全关闭它,您需要关闭关联的终端。更详细地说,Jupyter Notebook应用程序是一台服务器,显示在浏览器中的默认地址(http:// localhost:8888)。关闭浏览器不会关闭服务器。您可以重新打开以前的地址,然后Jupyter Notebook应用将重新显示。您可以运行Jupyter Notebook应用程序的许多副本,它们将显示在相似的地址上(只有端口“:”之后的数字才会为每个新副本递增)。由于只有一个Jupyter Notebook App,您已经可以打开许多笔记本,因此我们不建议您运行Jupyter Notebook App的多个副本。

摘要:其次,退出您从其发射Jupyter的终端。

I am copy pasting from the Jupyter/IPython Notebook Quick Start Guide Documentation, released on Feb 13, 2018. http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html

1.3.3 Close a notebook: kernel shut down 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).

Summary: First close and halt the notebooks running.

1.3.2 Shut down the Jupyter Notebook App Closing the browser (or the tab) will not close the Jupyter Notebook App. To completely shut it down you need to close the associated terminal. In more detail, the Jupyter Notebook App is a server that appears in your browser at a default address (http://localhost:8888). Closing the browser will not shut down the server. You can reopen the previous address and the Jupyter Notebook App will be redisplayed. You can run many copies of the Jupyter Notebook App and they will show up at a similar address (only the number after “:”, which is the port, will increment for each new copy). Since with a single Jupyter Notebook App you can already open many notebooks, we do not recommend running multiple copies of Jupyter Notebook App.

Summary: Second, quit the terminal from which you fired Jupyter.


回答 11

步骤1-在shell上,只需执行control + z(control + c)步骤2 _关闭Web浏览器

Step 1 – On shell just do control+z (control+c) Step 2 _ close the web browser


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。