在Colab中用jupyter nbconvert执行Drive挂载ipynb超时问题
Colab中使用nbconvert批量执行笔记本时
drive.mount超时问题 我在Colab中尝试通过一个笔记本依次执行多个ipynb笔记本,使用的代码如下:
from google.colab import drive drive.mount('/content/gdrive') !jupyter nbconvert --to notebook --ExecutePreprocessor.timeout=600 --execute "/content/drive/My Drive/Mike Education/Code/Extract/Reading Levels/Read in Cleaned Reading Levels Data.ipynb"
执行过程中出现超时错误,但手动运行目标笔记本仅需不到10分钟即可完成。调试信息显示超时发生在drive.mount步骤,完整错误日志如下:
[NbConvertApp] Searching ['/root/.jupyter', '/root/.local/etc/jupyter', '/usr/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter'] for config files [NbConvertApp] Looking for jupyter_config in /etc/jupyter [NbConvertApp] Looking for jupyter_config in /usr/local/etc/jupyter [NbConvertApp] Looking for jupyter_config in /usr/etc/jupyter [NbConvertApp] Looking for jupyter_config in /root/.local/etc/jupyter [NbConvertApp] Looking for jupyter_config in /root/.jupyter [NbConvertApp] Looking for jupyter_nbconvert_config in /etc/jupyter [NbConvertApp] Looking for jupyter_nbconvert_config in /usr/local/etc/jupyter [NbConvertApp] Looking for jupyter_nbconvert_config in /usr/etc/jupyter [NbConvertApp] Looking for jupyter_nbconvert_config in /root/.local/etc/jupyter [NbConvertApp] Looking for jupyter_nbconvert_config in /root/.jupyter [NbConvertApp] Converting notebook /content/drive/My Drive/Mike Education/Code/Extract/Reading Levels/Read in Cleaned Reading Levels Data.ipynb to notebook [NbConvertApp] Notebook name is 'Read in Cleaned Reading Levels Data' [NbConvertApp] Applying preprocessor: ExecutePreprocessor [NbConvertApp] Starting kernel: ['/usr/bin/python3', '-m', 'ipykernel_launcher', '-f', '/tmp/tmp1x8jnmqk.json', '--HistoryManager.hist_file=:memory:'] [NbConvertApp] Connecting to: tcp://127.0.0.1:47431 [NbConvertApp] connecting iopub channel to tcp://127.0.0.1:45195 [NbConvertApp] Connecting to: tcp://127.0.0.1:45195 [NbConvertApp] connecting shell channel to tcp://127.0.0.1:44753 [NbConvertApp] Connecting to: tcp://127.0.0.1:44753 [NbConvertApp] connecting stdin channel to tcp://127.0.0.1:55067 [NbConvertApp] Connecting to: tcp://127.0.0.1:55067 [NbConvertApp] connecting heartbeat channel to tcp://127.0.0.1:55431 [NbConvertApp] connecting control channel to tcp://127.0.0.1:47431 [NbConvertApp] Connecting to: tcp://127.0.0.1:47431 [NbConvertApp] Executing notebook with kernel: python3 [NbConvertApp] Executing cell: #imports import pandas as pd import numpy as np from google.colab import drive from google.colab import files import gspread import time import os from google.colab import auth auth.authenticate_user() import gspread from google.auth import default creds, _ = default() gc = gspread.authorize(creds) from oauth2client.client import GoogleCredentials drive.mount('/content/drive') [NbConvertApp] msg_type: status [NbConvertApp] content: {'execution_state': 'busy'} [NbConvertApp] msg_type: execute_input [NbConvertApp] content: {'code': "#imports\nimport pandas as pd\nimport numpy as np\nfrom google.colab import drive\nfrom google.colab import files\nimport gspread\nimport time\nimport os\nfrom google.colab import auth\nauth.authenticate_user()\n\nimport gspread\nfrom google.auth import default\ncreds, _ = default()\n\ngc = gspread.authorize(creds)\nfrom oauth2client.client import GoogleCredentials\n\ndrive.mount('/content/drive')\n", 'execution_count': 1} [NbConvertApp] ERROR | Timeout waiting for execute reply (600s). [NbConvertApp] Kernel is taking too long to finish, terminating Traceback (most recent call last): File "/usr/local/bin/jupyter-nbconvert", line 8, in <module> sys.exit(main()) File "/usr/local/lib/python3.8/dist-packages/jupyter_core/application.py", line 277, in launch_instance return super().launch_instance(argv=argv, **kwargs) File "/usr/local/lib/python3.8/dist-packages/traitlets/config/application.py", line 992, in launch_instance app.start() File "/usr/local/lib/python3.8/dist-packages/nbconvert/nbconvertapp.py", line 340, in start self.convert_notebooks() File "/usr/local/lib/python3.8/dist-packages/nbconvert/nbconvertapp.py", line 510, in convert_notebooks self.convert_single_notebook(notebook_filename) File "/usr/local/lib/python3.8/dist-packages/nbconvert/nbconvertapp.py", line 481, in convert_single_notebook output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer) File "/usr/local/lib/python3.8/dist-packages/nbconvert/nbconvertapp.py", line 410, in export_single_notebook output, resources = self.exporter.from_filename(notebook_filename, resources=resources) File "/usr/local/lib/python3.8/dist-packages/nbconvert/exporters/exporter.py", line 179, in from_filename return self.from_file(f, resources=resources, **kw) File "/usr/local/lib/python3.8/dist-packages/nbconvert/exporters/exporter.py", line 197, in from_file return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw) File "/usr/local/lib/python3.8/dist-packages/nbconvert/exporters/notebook.py", line 32, in from_notebook_node nb_copy, resources = super(NotebookExporter, self).from_notebook_node(nb, resources, **kw) File "/usr/local/lib/python3.8/dist-packages/nbconvert/exporters/exporter.py", line 139, in from_notebook_node nb_copy, resources = self._preprocess(nb_copy, resources) File "/usr/local/lib/python3.8/dist-packages/nbconvert/exporters/exporter.py", line 316, in _preprocess nbc, resc = preprocessor(nbc, resc) File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/base.py", line 47, in __call__ return self.preprocess(nb, resources) File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/execute.py", line 405, in preprocess nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources) File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/base.py", line 69, in preprocess nb.cells[index], resources = self.preprocess_cell(cell, resources, index) File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/execute.py", line 438, in preprocess_cell reply, outputs = self.run_cell(cell, cell_index, store_history) File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/execute.py", line 571, in run_cell if self._passed_deadline(deadline): File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/execute.py", line 541, in _passed_deadline self._handle_timeout() File "/usr/local/lib/python3.8/dist-packages/nbconvert/preprocessors/execute.py", line 504, in _handle_timeout raise TimeoutError("Cell execution timed out") TimeoutError: Cell execution timed out
已确认以下事项:
- 文件支持任何拥有链接的用户访问
- 目标笔记本手动运行完全正常
- 仅个人使用该Drive
- 推测内核均为Python 3,但不确定如何验证
内容的提问来源于stack exchange,提问作者elcunyado
相关产品推荐
相关产品推荐

