简体   繁体   English

如何使用 ipywidgets fileupload 上传大文件?

[英]How to upload a large file using the ipywidgets fileupload?

There is a server with Jupyterhub.有一个带有 Jupyterhub 的服务器。 It has remote access via a browser (IP address ONLY).它可以通过浏览器进行远程访问(仅限 IP 地址)。 User can upload large files (several GB) using the ipywidgets.fileupload.用户可以使用 ipywidgets.fileupload 上传大文件(几 GB)。 But I can't normally upload files more 100MB: Files abouts 200MB upload ~10 minutes.但我不能正常上传超过 100MB 的文件:大约 200MB 的文件上传约 10 分钟。 (scp command - less 2 minutes.). (scp 命令 - 少于 2 分钟。)。 Files more 250MB - ending with kernel error (but jupyterhub with "--debug" doesn't show anything).文件更多 250MB - 以 kernel 错误结尾(但带有“--debug”的 jupyterhub 不显示任何内容)。

Browser console error:浏览器控制台错误:

API request failed (0): error
:8000/user/aleksandr/api/contents/Untitled1.ipynb:1 Failed to load resource: net::ERR_EMPTY_RESPONSE
main.min.js?v=eef572336006937e9a017afbdebc65fe:24805 Uncaught (in promise) XhrError: error
    at wrap_ajax_error (http://192.168.1.49:8000/user/aleksandr/static/notebook/js/main.min.js?v=eef572336006937e9a017afbdebc65fe:24805:29)
    at Object.settings.error (http://192.168.1.49:8000/user/aleksandr/static/notebook/js/main.min.js?v=eef572336006937e9a017afbdebc65fe:24861:24)
    at u (http://192.168.1.49:8000/user/aleksandr/static/notebook/js/main.min.js?v=eef572336006937e9a017afbdebc65fe:2:27457)
    at Object.fireWith [as rejectWith] (http://192.168.1.49:8000/user/aleksandr/static/notebook/js/main.min.js?v=eef572336006937e9a017afbdebc65fe:2:28202)
    at k (http://192.168.1.49:8000/user/aleksandr/static/notebook/js/main.min.js?v=eef572336006937e9a017afbdebc65fe:2:77676)
    at XMLHttpRequest.<anonymous> (http://192.168.1.49:8000/user/aleksandr/static/notebook/js/main.min.js?v=eef572336006937e9a017afbdebc65fe:2:79882)
wrap_ajax_error @ main.min.js?v=eef572336006937e9a017afbdebc65fe:24805
settings.error @ main.min.js?v=eef572336006937e9a017afbdebc65fe:24861
u @ main.min.js?v=eef572336006937e9a017afbdebc65fe:2
fireWith @ main.min.js?v=eef572336006937e9a017afbdebc65fe:2
k @ main.min.js?v=eef572336006937e9a017afbdebc65fe:2
(anonymous) @ main.min.js?v=eef572336006937e9a017afbdebc65fe:2

Some source code:一些源代码:

import ipywidgets as widgets

def ff(b):
    s.style.button_color = "yellow"
    for elem in b.new.values():
        print(elem['metadata']['name'])
        with open(elem['metadata']['name'], 'wb') as file:
            file.write( elem['content'])
        print("Done")
    s.style.button_color = "lightgreen"

s = widgets.FileUpload(
    accept='',  # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf'
    multiple=True  # True to accept multiple files upload else False
)
s.style.button_color = "lightgreen"
s.observe(ff, names='value')
s

When freezing, the "ff" function is not executed.冻结时,不执行“ff” function。

I use:我用:

  • python: 3.7.3 python:3.7.3
  • jupyter core:4.5.0 jupyter核心:4.5.0
  • jupyter-notebook: 6.0.0 jupyter-notebook:6.0.0
  • ipython: 7.6.1 ipython:7.6.1
  • ipykernel: 5.1.1 ipykernel:5.1.1
  • ipywidgets: 7.5.0 ipywidgets:7.5.0
  • jupyterhub: 1.0.0 jupyterhub:1.0.0

Some action:一些动作:

According this: https://github.com/jupyter-widgets/ipywidgets/issues/2522 , I changed in jupyer_config.py:根据这个: https://github.com/jupyter-widgets/ipywidgets/issues/2522 ,我在jupyer_config.py中进行了更改:

c.Spawner.args=['--SingleUserNotebookApp.tornado_settings = {"websocket_max_message_size": 1073741824}']

Execution at startup of a user's notebook.在用户笔记本启动时执行。 And:和:

c.JupyterHub.tornado_settings= {"websocket_max_message_size": 1073741824}}

In general, changing these fields did not affect the state of the problem.一般来说,更改这些字段不会影响问题的 state。

Is it possible to upload large files with normal speed through the ipywidgets.fileupload?是否可以通过 ipywidgets.fileupload 以正常速度上传大文件?

The solution to the problem is still an open issue in Jupyter Community.该问题的解决方案在 Jupyter 社区中仍然是一个未解决的问题。
But there is a workaround available, ie to increase the websocket message size that tornado supports.但是有一个可用的解决方法,即增加tornado 支持的websocket 消息大小。

Please refer to this link .请参考此链接

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

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