# Fix VS Code Jupyter Notebook Kernel Disconnected From Session
You are working in a Jupyter Notebook inside VS Code, and suddenly all cells show a "Not Connected" status. The kernel indicator in the top right shows "Disconnected" or "Starting" indefinitely. Output from previously running cells is lost, and new cells cannot be executed.
Step 1: Check the Kernel Status
Look at the kernel indicator in the top-right corner of the notebook editor. It shows:
- Python 3.11.x -- Kernel is connected
- Starting... -- Kernel is launching
- Disconnected -- Connection lost
- Select Kernel -- No kernel selected
Click on the kernel indicator to see available kernels and the connection status.
Step 2: Check the Jupyter Output Panel
Open the Jupyter output panel:
View > Output > Select "Jupyter" from dropdownThis shows the complete kernel lifecycle:
Info: Starting kernel python311-jvsc74a57bd9-...
Info: Kernel started: abc123
Error: Kernel connection timed out after 60 seconds
Error: Kernel process exited with code 1Common errors: - Timeout: Kernel took too long to start - Process exited: Python process crashed - Connection lost: Network or IPC issue
Step 3: Kernel Process Crashed
If the kernel process crashed, check the Python environment:
```bash # Check if Python is working /path/to/venv/bin/python --version
# Check if ipykernel is installed /path/to/venv/bin/python -m ipykernel --version
# If not installed /path/to/venv/bin/python -m pip install ipykernel ```
The Jupyter kernel requires the ipykernel package. Without it, the kernel cannot start.
Step 4: Reconnect the Kernel
Try reconnecting without restarting:
- 1.Click the kernel indicator in the top right
- 2.Select the same kernel again
- 3.VS Code attempts to reconnect
If that fails, restart the kernel:
Jupyter: Restart KernelFrom the Command Palette. This kills the current kernel process and starts a new one.
Step 5: Memory Exhaustion
The most common cause of kernel crashes is memory exhaustion. If a cell loads a large dataset:
import pandas as pd
df = pd.read_csv('huge_dataset.csv') # 4GB file on a 8GB machineThe kernel process exceeds available memory and gets killed by the OS.
Check system memory:
free -hIf memory is critically low, the OOM killer terminates the kernel:
sudo dmesg -T | grep -i "killed process" | grep pythonFix by:
- Using chunked reading: pd.read_csv('file.csv', chunksize=10000)
- Increasing system memory or swap
- Using a more memory-efficient library (Dask, Polars)
Step 6: Python Environment Changed
If you updated Python, changed virtual environments, or removed packages, the kernel may no longer work:
# Check if the kernel's Python still exists
cat ~/.local/share/jupyter/kernels/python3/kernel.json
# Shows the Python executable pathIf the executable no longer exists, reinstall ipykernel:
/path/to/venv/bin/python -m ipykernel install --user --name=my-venv --display-name="Python (my-venv)"Then select the newly registered kernel in VS Code.
Step 7: Jupyter Extension Issues
The VS Code Jupyter extension may need an update or restart:
Extensions > Search: JupyterCheck for updates. If the extension was recently updated, reload the window:
Developer: Reload WindowStep 8: Clear Notebook Output
Corrupted cell output can cause kernel connection issues. Clear all output:
Jupyter: Clear All OutputsThen restart the kernel. If the connection stabilizes, a specific cell's output was causing the problem.
Step 9: Disable Pre-warming
VS Code pre-warms kernels to speed up notebook opening. This can cause connection issues:
{
"jupyter.disableJupyterAutoStart": true
}With this setting, kernels only start when you explicitly run a cell. This is slower but more reliable.
Step 10: Remote Kernel Connection
For remote Jupyter kernels:
{
"jupyter.jupyterServerType": "remote",
"jupyter.remoteJupyterServers": [
{
"baseUrl": "http://remote-server:8888/",
"token": "your-token-here"
}
]
}If the remote server is unreachable, the kernel shows as disconnected. Verify:
curl http://remote-server:8888/api/kernelsIf this fails, the remote Jupyter server is down or the network is unreachable.