简体   繁体   English

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

[英]Jupyter notebook keeps reconnecting to kernel

I get to open the Jupyter console without any problems, but when I create a new notebook it keeps connecting to and disconnecting from the kernel (the messages "Connecting to Kernel" / "Connected" keep showing in the upper right corner).我可以毫无问题地打开 Jupyter 控制台,但是当我创建一个新笔记本时,它会不断连接到内核并断开与内核的连接(消息“连接到内核”/“已连接”一直显示在右上角)。 This is what Chrome's console spits out (it's the same in Firefox):这是 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 ... #

Thing is, everything works fine when I create a notebook on the same machine that runs the Jupyter server (a MacBook I keep at home).事情是,当我在运行 Jupyter 服务器的同一台机器(我放在家里的 MacBook)上创建笔记本时,一切正常。 The problem happens when I create a notebook from a different machine (a PC running Windows that I use at my company).当我从另一台机器(我公司使用的运行 Windows 的 PC)创建笔记本时,就会出现问题。 What could be going on?会发生什么?

I'm using jupyter behind a nginx proxy.我在 nginx 代理后面使用 jupyter。 I met the same problem as you are.我遇到了和你一样的问题。 After drill down, I find the problem is existed in my nginx conf.深入研究后,我发现问题存在于我的 nginx conf 中。

After adding the following line to my nginx conf, it works!将以下行添加到我的 nginx conf 后,它可以工作了!

proxy_http_version 1.1; proxy_http_version 1.1;

Here's the complete nginx conf:这是完整的 nginx 配置:

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;
  }
}

I don't known why it happens since the old version without proxy_http_version 1.1;我不知道为什么会发生这种情况,因为没有proxy_http_version 1.1;的旧版本proxy_http_version 1.1; worked well in last few months before I met the issue.在我遇到这个问题之前的最后几个月工作得很好。

I've just changed the port from 8888 to 9999, and the problem is gone.我刚刚将端口从 8888 更改为 9999,问题就消失了。

use the command使用命令

jupyter notebook --generate-config

(it says where the generated config file is) (它说明生成的配置文件在哪里)

to generate a config file, then find the line生成一个配置文件,然后找到该行

c.NotebookApp.port

and change the port.并更改端口。

Optionally, you can specify the port number directly when starting the server:或者,您可以在启动服务器时直接指定端口号:

jupyter notebook --port=9999

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM