microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.3k stars 294 forks source link

Kernel Crash #16132

Closed fchareyr closed 4 weeks ago

fchareyr commented 1 month ago

Applies To

What happened?

I have a Notebook that crashes when executed within VS Code either as a notebook or a Cell Script. However, it works just fine as a script or a Notebook ran on Jupyter (launched from the same environment).

This happens on a Linux (Fedora, Red Hat) machine, accessed via SSH. The exact same setup causes no issue on a Windows machine.

The log from the Jupyter extension in VS Code:

11:09:03.917 [info] Restarted 870b1b0b-cd40-477b-816a-5c0263f6441e 11:09:03.975 [debug] Requesting Kernel info 11:09:09.277 [debug] Handle Execution of Cells 0 for ~/.../my_notebook.ipynb 11:09:09.281 [debug] Kernel acknowledged execution of cell 0 @ 1729242549281 11:09:10.498 [debug] KernelProcess Exited 250997, Exit Code - undefined 11:09:10.499 [error] Disposing session as kernel process died ExitCode: undefined, Reason: 11:09:10.499 [debug] Dispose Kernel process 250997. 11:09:10.515 [debug] Disposed Kernel process 250997.

The error message within the Notebook cell's output in VS Code:

The Kernel crashed while executing code in the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details.

VS Code Version

1.94.2

Jupyter Extension Version

v2024.9.1

Jupyter logs

11:09:03.917 [info] Restarted 870b1b0b-cd40-477b-816a-5c0263f6441e 11:09:03.975 [debug] Requesting Kernel info 11:09:09.277 [debug] Handle Execution of Cells 0 for ~/.../my_notebook.ipynb 11:09:09.281 [debug] Kernel acknowledged execution of cell 0 @ 1729242549281 11:09:10.498 [debug] KernelProcess Exited 250997, Exit Code - undefined 11:09:10.499 [error] Disposing session as kernel process died ExitCode: undefined, Reason: 11:09:10.499 [debug] Dispose Kernel process 250997. 11:09:10.515 [debug] Disposed Kernel process 250997.

Coding Language and Runtime Version

Python v.3.9.19

Language Extension Version (if applicable)

No response

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

None

DonJayamanne commented 1 month ago

Please could you enable logging as follows:

Also, please can you share the mininal sample code to replicate this issue.

fchareyr commented 1 month ago

Thanks for the swift reply. The asked log are below. Unfortunately, I cannot share the minimal sample code but it is essentially importing a private library.

Visual Studio Code (1.94.2, ssh-remote, desktop)
Jupyter Extension Version: 2024.9.1.
Python Extension Version: 2024.16.1.
Pylance Extension Version: 2024.10.1.
Platform: linux (x64).
Temp Storage folder ~/.vscode-server/data/User/globalStorage/ms-toolsai.jupyter/version-2024.9.1
Workspace folder ~/***/***, Home = /home/***
17:15:41.637 [debug] Start refreshing Kernel Picker (1729264541637)
17:15:41.681 [trace] Search for KernelSpecs in Interpreter ~/.cache/pypoetry/virtualenvs/***-***-py3.12/bin/python
17:15:41.682 [trace] Search for KernelSpecs in Interpreter ~/.pyenv/versions/3.12.5/bin/python
17:15:41.682 [trace] Search for KernelSpecs in Interpreter ~/.pyenv/versions/3.9.19/bin/python
17:15:41.682 [trace] Search for KernelSpecs in Interpreter /bin/python
17:15:41.683 [trace] Search for KernelSpecs in Interpreter /usr/bin/python
17:15:41.683 [trace] Search for KernelSpecs in Interpreter ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python
17:15:41.684 [debug] Get Custom Env Variables, Class name = Cm, completed in 48ms, has a truthy return value, Arg 1: undefined, Arg 2: "RunPythonCode"
17:15:41.684 [debug] Jupyter Paths /kernels: 
17:15:41.685 [debug] Kernel Spec Root Paths, /usr/share/jupyter/kernels, /usr/local/share/jupyter/kernels, ~/.local/share/jupyter/kernels
17:15:41.744 [trace] Conda file is conda
17:15:41.745 [trace] Hiding default KernelSpec /python for interpreter ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python (KernelSpec file ~/.cache/pypoetry/virtualenvs/***-***-py3.9/share/jupyter/kernels/python3/kernel.json)
17:15:41.745 [debug] End refreshing Kernel Picker (1729264541637)
17:15:41.787 [debug] KernelProvider switched kernel to id = .jvsc74a57bd0858439c8e486e8a3c17b8ac9923e6038f65030471333a23858c2ae1fd92ce16c./home/~/.cache/pypoetry/virtualenvs/***-***-py3.9/python./home/~/.cache/pypoetry/virtualenvs/***-***-py3.9/python.-m#ipykernel_launcher
17:15:41.787 [debug] start the kernel, options.disableUI=true for ~/***/***/***/***/**/***/***.ipynb
17:15:41.801 [trace] Registering commtarget jupyter.widget
17:15:41.802 [debug] Controller selection change completed
17:15:41.811 [debug] Get Custom Env Variables, Class name = Cm, completed in 0ms, has a truthy return value, Arg 1: "~/***/***", Arg 2: "RunPythonCode"
17:15:41.812 [info] Starting Kernel (Python Path: ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python, Poetry, 3.9.19) for '~/***/***/***/***/***/***/***.ipynb' (disableUI=true)
17:15:41.812 [trace] Creating raw notebook for resource '~/***/***/***/***/***/***/***.ipynb'
17:15:41.820 [debug] Get Custom Env Variables, Class name = Cm, completed in 0ms, has a truthy return value, Arg 1: "~/***/***/***/***/***/***/***.ipynb", Arg 2: "RunPythonCode"
17:15:41.826 [debug] Launching kernel .jvsc74a57bd0858439c8e486e8a3c17b8ac9923e6038f65030471333a23858c2ae1fd92ce16c./home/~/.cache/pypoetry/virtualenvs/***-***-py3.9/python./home/~/.cache/pypoetry/virtualenvs/***-***-py3.9/python.-m#ipykernel_launcher for ~/***/***/***/***/***/***/***.ipynb in //home/~/***/***/***/***/***/***with ports 9001, 9000, 9004, 9002, 9003
17:15:41.930 [debug] Got env vars from Python Ext in 119ms for ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python, with env var count 63.
17:15:41.930 [trace] Prepend PATH with python bin for ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python
17:15:41.931 [debug] Getting activated env variables, Class name = gd, completed in 120ms, has a truthy return value, Arg 1: "~/***/***", Arg 2: "~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python", Arg 3: undefined
17:15:41.935 [info] Process Execution: ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python -m pip list
17:15:41.941 [debug] Got env vars from Python Ext in 121ms for ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python, with env var count 63.
17:15:41.942 [trace] Prepend PATH with python bin for ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python
17:15:41.942 [debug] Getting activated env variables, Class name = gd, completed in 122ms, has a truthy return value, Arg 1: "~/***/***/***/***/***/***/***.ipynb", Arg 2: "~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python", Arg 3: undefined
17:15:41.945 [info] Process Execution: ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
17:15:41.949 [info] Process Execution: ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python -m ipykernel_launcher --f=/home/~/.local/share/jupyter/runtime/kernel-v38a06577b97e5f4ace1c9950126cda600f21259a5.json
    > cwd: //home/~/***/***/***/***/***/***
17:15:41.949 [debug] Kernel process 258884.
17:15:42.056 [trace] ipykernel version & path 6.29.5, ~/.cache/pypoetry/virtualenvs/***-***-py3.9/lib/python3.9/site-packages/ipykernel/__init__.py for ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python
17:15:42.230 [debug] Kernel output 258884: To connect another client to this kernel, use:
--existing kernel-v38a06577b97e5f4ace1c9950126cda600f21259a5.json
17:15:42.378 [debug] Waiting for Raw Session to be ready in postStartRawSession
17:15:42.378 [debug] Waiting for Raw session to be ready, status: connected
17:15:42.379 [trace] Raw session connected
17:15:42.379 [debug] Waited for Raw session to be ready & got status: connected
17:15:42.379 [debug] Successfully waited for Raw Session to be ready in postStartRawSession
17:15:42.379 [debug] Kernel status is 'unknown' before requesting kernel info and after ready
17:15:42.379 [debug] Sending request for kernelInfo
17:15:42.387 [trace] Got response for requestKernelInfo
17:15:42.387 [debug] Successfully completed postStartRawSession after 1 attempt(s) in 8ms
17:15:42.388 [trace] Executing silently Code (idle) = import sys as _VSCODE_sys\nprint(_VSCODE_sys.executable); del _VSCODE_sys
17:15:42.402 [trace] Executing silently Code (completed) = import sys as _VSCODE_sys\nprint(_VSCODE_sys.executable); del _VSCODE_sys with 1 output(s)
17:15:42.402 [trace] Started running kernel initialization for ~/***/***/***/***/***/***/***.ipynb
17:15:42.403 [trace] Executing silently Code (idle) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy
17:15:42.443 [trace] Executing silently Code (completed) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy with 1 output(s)
17:15:42.443 [trace] Determined IPyWidgets Version as 8
17:15:42.444 [trace] Version of IPyWidgets 8 determined after 0.643s
17:15:42.444 [trace] Executing silently Code (idle) = def __VSCODE_inject_module():\ndef __VSCODE_call_function(function, callback, data=None):
17:15:42.454 [trace] Executing silently Code (completed) = def __VSCODE_inject_module():\ndef __VSCODE_call_function(function, callback, data=None): with 0 output(s)
17:15:42.455 [debug] Requesting Kernel info
17:15:42.455 [trace] Got Kernel info
17:15:42.455 [trace] End running kernel initialization, now waiting for idle
17:15:42.455 [trace] Waiting for idle on (kernel): 7a21cb05-98b7-4701-aa50-e009f2214faa -> idle
17:15:42.455 [trace] Finished waiting for idle on (kernel): 7a21cb05-98b7-4701-aa50-e009f2214faa -> idle
17:15:42.456 [trace] End running kernel initialization, session is idle
17:15:42.456 [trace] Registering Kernel Completion Provider from kernel ***-***-py3.9 (Python 3.9.19) for language python
17:15:42.457 [trace] IPyWidgetScriptSource.initialize
17:15:42.457 [info] Kernel successfully started
17:15:42.458 [debug] getDataDirsImpl, Class name = Mr (started execution), Arg 1: "~/***/***/***/***/***/***/***.ipynb", Arg 2: "~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python"
17:15:42.459 [debug] Get Custom Env Variables, Class name = Cm, completed in 1ms, has a truthy return value, Arg 1: undefined, Arg 2: "RunPythonCode"
17:15:42.459 [debug] Jupyter Paths : 
17:15:42.462 [info] Process Execution: ~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python /home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/pythonFiles/printJupyterDataDir.py
17:15:42.475 [debug] Got an empty Jupyter Data Dir from /home/~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python, stderr = undefined
17:15:42.475 [debug] getDataDirsImpl, Class name = Mr, completed in 17ms, has a truthy return value, Arg 1: "~/***/***/***/***/***/***/***.ipynb", Arg 2: "~/.cache/pypoetry/virtualenvs/***-***-py3.9/bin/python", Return Value: <Uri:/home/~/.local/share/jupyter>, <Uri:/home/~/.cache/pypoetry/virtualenvs/***-***-py3.9/share/jupyter>, <Uri:/usr/local/share/jupyter>, <Uri:/usr/share/jupyter>
17:15:42.984 [trace] Web view is ready to receive widget messages
17:15:42.997 [trace] Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
17:15:42.997 [trace] Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
17:15:43.000 [trace] Widget Message: data-base-url set to https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter
17:15:43.000 [trace] Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
17:15:43.000 [trace] Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
17:15:43.000 [trace] Widget Message: data-base-url set to https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter
17:15:43.006 [trace] Widget Message: Received IPyWidget scripts [{"moduleName":"anywidget","scriptUri":"https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/anywidget/index","source":"local"}]
17:15:43.006 [trace] Widget Message: Source for IPyWidget anywidget found in local @ https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/anywidget/index.
17:15:43.006 [trace] Widget Message: Registering IPyWidget anywidget found in https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/anywidget/index.
17:15:43.006 [trace] Widget Message: Received IPyWidget scripts [{"moduleName":"jupyter-tablewidgets","scriptUri":"https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/jupyter-tablewidgets/index","source":"local"}]
17:15:43.007 [trace] Widget Message: Source for IPyWidget jupyter-tablewidgets found in local @ https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/jupyter-tablewidgets/index.
17:15:43.007 [trace] Widget Message: Registering IPyWidget jupyter-tablewidgets found in https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/jupyter-tablewidgets/index.
17:15:43.007 [trace] Widget Message: Received IPyWidget scripts [{"moduleName":"jupyterlab-plotly","scriptUri":"https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/jupyterlab-plotly/index","source":"local"}]
17:15:43.007 [trace] Widget Message: Source for IPyWidget jupyterlab-plotly found in local @ https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/jupyterlab-plotly/index.
17:15:43.007 [trace] Widget Message: Registering IPyWidget jupyterlab-plotly found in https://***.vscode-resource.vscode-cdn.net/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.9.1-linux-x64/temp/scripts/84a15a2e817366b5aece384617caaa75beb2c1cc0e8d947b7257df978240add6/jupyter/nbextensions/jupyterlab-plotly/index.
17:15:43.245 [debug] Handle Execution of Cells 0 for ~/***/***/***/***/***/***/***.ipynb
17:15:43.247 [trace] Execute Notebook ~/***/***/***/***/***/***/***.ipynb. Step 1
17:15:43.247 [trace] Connect to Kernel ~/***/***/***/***/***/***/***.ipynb. Step 2
17:15:43.248 [trace] Connected to Kernel ~/***/***/***/***/***/***/***.ipynb. Step 3
17:15:43.249 [trace] executeCell 0. Step 4
17:15:43.251 [trace] Cell Index:0 sent to kernel
17:15:43.274 [trace] Start cell 0 execution @ 1729264543274 (clear output)
17:15:43.274 [debug] Kernel acknowledged execution of cell 0 @ 1729264543274
17:15:44.615 [debug] KernelProcess Exited 258884, Exit Code - undefined 
17:15:44.616 [error] Disposing session as kernel process died ExitCode: undefined, Reason: 
17:15:44.616 [debug] Dispose Kernel process 258884.
17:15:44.641 [debug] Disposed Kernel process 258884.
17:15:44.688 [trace] Cell 0 completed in -1729264543.274s (start: 1729264543274, end: undefined)
DonJayamanne commented 1 month ago

Unfortunately, I cannot share the minimal sample code but it is essentially importing a private library.

This will be very difficult to resolve. let me try my best. Does this package rely on some environment variables, thats the only possible reason for the failure or the python environment used is not the same.

fchareyr commented 4 weeks ago

Thanks @DonJayamanne for your help, the issue was due to missing environment variables when using the Jupyter extension.