jupyter-notebook - 在 WSL2 上与 Jupyter Notebook 的连接缓慢
问题描述
我在 WSL2 实例中运行 Jupyter 笔记本时遇到了一个奇怪的问题。每次我启动一个新笔记本时,我第一次连接localhost:8888
(或localhost:XXXX
任何其他端口号)需要很长时间才能连接,比如 5-10 分钟。但是,一旦与该端口建立了一个连接,所有后续连接都会以正常速度发生。GET
据我所知,延迟并没有具体发生在 Jupyter 服务器中,因为服务器输出在等待期间没有显示任何请求:
> jupyter notebook .
[I 08:29:21.282 NotebookApp] Authentication of /metrics is OFF, since other authentication is disabled.
[W 08:29:21.729 NotebookApp] All authentication is disabled. Anyone who can connect to this server will be able to run code.
[I 08:29:21.732 NotebookApp] Serving notebooks from local directory: /home/peter/jade_poplar/code/python
[I 08:29:21.732 NotebookApp] Jupyter Notebook 6.4.0 is running at:
[I 08:29:21.732 NotebookApp] http://localhost:8888/
[I 08:29:21.732 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
...
5-10 MINUTES ELAPSE
...
[I 08:38:12.718 NotebookApp] 302 GET / (127.0.0.1) 2.110000ms
但是,问题似乎仅限于 Jupyter:如果我只是在端口上侦听,然后将nc -l 8888
浏览器指向请求,则会立即出现。localhost:8888
GET
我已经尝试随机修复我在 SE 上发现的其他问题,例如。这一个,但无济于事。任何建议,甚至是关于从哪里开始寻找的建议,将不胜感激!这让我发疯了,虽然我在等待笔记本加载时下棋很多:D
解决方案
更新
经过一些调试后,我发现该--no-browser
选项也可以解决问题:
jupyter notebook --no-browser .
jupyter-notebook
默认localhost:8888
在浏览器中打开。我认为 WSL2 在打开默认浏览器时出现问题,因此会超时。
旧答案
我找到了两种方法来解决我系统上的“等待时间”。
- 在控制台输出挂起后按Ctrl+C一次
Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
- 将
DISPLAY
环境变量设置为空:DISPLAY= jupyter notebook .
. 显然,同样的技巧适用于 pip。
推荐阅读
- .htaccess - Can I do multiple error handling with single line code on .htaccess?
- java - JavaFX: New line spacing between texts in TextFlow
- git - git unable to open connection
- r - 如何将两个小标题乘以列名
- r - R- Move values to same row and keep dataframe structure
- c - Why does fopen() use strings instead of enums?
- bash - 在 for 循环中连接数组的元素
- javascript - 如何模拟对组件的点击?
- c++ - 当我不关心订单并且没有重复项时,更快的擦除删除习语?
- python - 如何立即将所有 Snakemake 作业提交到 slurm 集群