Jupyter笔记本不断重新连接到内核

时间:2017-02-20 16:54:45

标签: python ipython jupyter

我可以毫无问题地打开Jupyter控制台,但是当我创建一个新的笔记本时,它会一直连接到内核并与内核断开连接(消息"连接到内核" /"已连接&# 34;继续显示在右上角)。这就是Chrome的控制台吐出的内容(在Firefox中也是如此):

Untitled3.ipynb?kernel_name=python3:121 loaded custom.js
default.js:48Default extension for cell metadata editing loaded.
rawcell.js:82Raw Cell Format toolbar preset loaded.
slideshow.js:43Slideshow extension for metadata editing loaded.
menubar.js:240actions jupyter-notebook:find-and-replace does not exist, still binding it in case it will be defined later...
MenuBar.bind_events @ menubar.js:240
extension.js Failed to load resource: the server responded with a status of 404 (Not Found)
main.js:184Widgets are not available.  Please install widgetsnbextension or ipywidgets 4.0
(anonymous) @ main.js:184
session.js:54Session: kernel_created (1b236a4b-902d-4b33-9118-63013be4f270)
kernel.js:456Starting WebSockets: ws://[myipaddress]:[myport]/api/kernels/682dc980-d7c6-41e0-b984-14ceb7f8e50c
kernel.js:101Kernel: kernel_connected (682dc980-d7c6-41e0-b984-14ceb7f8e50c)
kernel.js:101Kernel: kernel_disconnected (682dc980-d7c6-41e0-b984-14ceb7f8e50c)
kernel.js:559Connection lost, reconnecting in 1 seconds.
kernel.js:101Kernel: kernel_reconnecting (682dc980-d7c6-41e0-b984-14ceb7f8e50c)
kernel.js:456Starting WebSockets: ws://[myipaddress]:[myport]/api/kernels/682dc980-d7c6-41e0-b984-14ceb7f8e50c
kernel.js:101Kernel: kernel_connected (682dc980-d7c6-41e0-b984-14ceb7f8e50c)
kernel.js:101Kernel: kernel_disconnected (682dc980-d7c6-41e0-b984-14ceb7f8e50c)
kernel.js:559Connection lost, reconnecting in 1 seconds.
kernel.js:101Kernel: kernel_reconnecting (682dc980-d7c6-41e0-b984-14ceb7f8e50c)
kernel.js:456Starting WebSockets: ws://[myipaddress]:[myport]/api/kernels/682dc980-d7c6-41e0-b984-14ceb7f8e50c
kernel.js:101Kernel: kernel_connected (682dc980-d7c6-41e0-b984-14ceb7f8e50c)
kernel.js:101Kernel: kernel_disconnected (682dc980-d7c6-41e0-b984-14ceb7f8e50c)
kernel.js:559Connection lost, reconnecting in 1 seconds.
# ... more of the same, over and over ... #

事实是,当我在运行Jupyter服务器的同一台机器上创建一个笔记本时,一切正常(我留在家里的MacBook)。当我从另一台机器(我在公司使用的运行Windows的PC)上创建笔记本时,会出现问题。会发生什么事?

2 个答案:

答案 0 :(得分:3)

我刚刚将端口从8888更改为9999,问题就消失了。

使用命令

jupyter notebook --generate-config

(它表示生成的配置文件在哪里)

生成配置文件,然后找到行

c.NotebookApp.port

并更改端口。

答案 1 :(得分:1)

我在nginx代理后面使用jupyter。我遇到了和你一样的问题。深入研究后,我发现问题存在于我的nginx conf。

将以下行添加到我的nginx conf后,它可以正常工作!

  

proxy_http_version 1.1;

这是完整的nginx conf:

upstream my-notebook-workhorse {
  server 127.0.0.1:8888 fail_timeout=0;
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

# let my-notebook deal with the redirection
server {
  listen                    80;
  server_name               my-notebook.wh;
  server_tokens             off;
  root                      /dev/null;

  # Increase this if you want to upload larger attachments
  client_max_body_size      20m;

  # individual nginx logs for this vhost
  access_log                /var/log/nginx/my-notebook_access.log;
  error_log                 /var/log/nginx/my-notebook_error.log;

  location / {
    proxy_pass http://my-notebook-workhorse;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    auth_basic "Restricted Content";

    # WebSocket support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Origin "";
    proxy_read_timeout 86400;
  }
}

我不知道为什么会发生这种情况,因为没有proxy_http_version 1.1;的旧版本在我遇到问题之前的最后几个月运作良好。