If your VS Code Python notebook is not responding, the most common cause is a hung kernel or a resource overload, and the first fix is to restart the kernel or reload the window. This article explains why notebooks freeze and gives step-by-step fixes for the usual culprits: kernel crashes, memory exhaustion, Jupyter server issues, and extension conflicts.
Why Notebooks Freeze in VS Code
VS Code runs Python notebooks through a Jupyter kernel—a separate process that executes your code and returns output. When the kernel stops responding, the notebook UI appears frozen: cells won’t run, the status bar shows “Kernel Busy” or “Idle” incorrectly, and clicking anything seems to do nothing. The kernel can hang for many reasons, but the most frequent are:
- An infinite loop or a long-running computation that never finishes
- Memory exhaustion (the kernel runs out of RAM and the OS stops responding)
- A crash in the Python interpreter or a native library
- The Jupyter server (or the VS Code extension host) becoming unresponsive
- Too many notebooks open or a huge notebook with many large outputs
Sometimes the notebook itself is fine but the VS Code window is frozen due to extension problems or a corrupted state. The steps below cover both cases.
Quick Fixes to Try First
- Restart the kernel – Click the kernel name in the top-right (e.g., “Python 3.12.4”) and choose “Restart Kernel”. If the UI is unresponsive, use the command palette (Ctrl+Shift+P) and type “Jupyter: Restart Kernel”.
- Reload the window – Press Ctrl+Shift+P and run “Developer: Reload Window”. This restarts the VS Code UI without closing your files.
- Stop the kernel from the terminal – If the UI is completely frozen, open a terminal (Ctrl+`) and run
jupyter kernelspec listto find the kernel, then kill the process. On Windows use Task Manager; on macOS/Linux usekill <PID>. - Close other notebooks – Each notebook uses its own kernel; too many open kernels can starve your system of memory.
Memory and CPU Overload
The most common cause of a non-responsive notebook is a cell that consumes all available RAM or CPU. For example, a while True loop without a break, or a list comprehension over a huge range, can make the kernel unresponsive. Even if your code is correct, loading a very large dataset (like a 10 GB CSV) into a pandas DataFrame can exhaust memory and make the whole system sluggish.
To avoid this:
- Use
top(Linux/macOS) or Task Manager (Windows) to see if the kernel process is using 100% CPU or most of your RAM. - If memory is the issue, reduce the data size (e.g., read only needed columns) or use chunking.
- For CPU-bound tasks, add a timeout or use
time.sleep()in loops to allow the UI to refresh. - Consider using the VS Code built-in memory view: click the kernel name and select “Show Kernel Memory” to see memory usage per cell.
Jupyter Server and Extension Issues
VS Code can connect to a local Jupyter server or a remote one. If the server is unreachable or crashed, the notebook will hang. Check the Output panel (View → Output) and select “Jupyter” from the dropdown to see error messages like “Connection refused” or “Kernel died”.
Common fixes:
- Restart the Jupyter server: run
jupyter server stopand thenjupyter server startin a terminal, or simply restart VS Code. - Disable and re-enable the Jupyter extension (Ctrl+Shift+X, search for “Jupyter”, click Disable, then Enable).
- Update the Jupyter extension and the Python extension to the latest versions.
- If you’re using a remote environment (SSH, WSL, or a container), check that the remote connection is stable and that the remote machine has enough resources.
When the Whole VS Code Window Freezes
If the entire editor becomes unresponsive (not just the notebook), the problem is likely in the extension host or a rendering issue. Try these in order:
- Press Ctrl+Shift+P to open the command palette. If it opens, run “Developer: Reload Window”.
- If the palette doesn’t open, force-quit VS Code and reopen it. Your unsaved changes may be lost, but notebooks are usually saved on disk.
- Disable all extensions temporarily: start VS Code with
code --disable-extensionsfrom a terminal. If the notebook works, re-enable extensions one by one to find the culprit. - Check for GPU/rendering issues: set
"workbench.enableExperiments": falseor disable hardware acceleration via"window.disableHardwareAcceleration": truein settings.
Preventing Future Freezes
Once your notebook is responsive again, adopt these habits to reduce the chance of it freezing:
- Run cells incrementally instead of running the entire notebook at once.
- Clear output regularly (Edit → Clear All Outputs) to keep the notebook file small.
- Use
%timeor%%timeto check cell execution time. - Set a timeout for long operations: e.g.,
from multiprocessing import TimeoutErroror usesignal.alarmon Unix. - Keep your Python environment and VS Code extensions updated.
- If you work with large data, consider using a tool like Dask or Polars that handles out-of-core computation.
Frequently Asked Questions
Why does my notebook say “Kernel Busy” forever?
This usually means the kernel is stuck on a cell that never finishes. Check the cell output for an infinite loop or a long computation. If you can’t interrupt it, restart the kernel.
Can I recover unsaved code if VS Code crashes?
VS Code has an auto-save feature for notebooks (default is on). Look for a backup file with the same name but a .ipynb~ extension in the same folder, or use “File → Revert File” to go back to the last saved version.
Why does the notebook work in Jupyter but not in VS Code?
This can happen if the VS Code Jupyter extension is not using the same Python environment as your Jupyter installation. Check the kernel selection and ensure it points to the environment where your packages are installed.
Is it safe to delete the .ipynb_checkpoints folder?
Yes, that folder contains auto-saved checkpoints. Deleting it won’t affect your notebook, but you’ll lose the ability to revert to a previous checkpoint.
How do I change the kernel to avoid crashes?
Click the kernel name in the top-right and select a different environment. If you’re using a conda environment, make sure it’s listed in the kernel picker. You can also create a new kernel with python -m ipykernel install --user --name myenv.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Hide PHP Version HTTP Header: How To
- CentOS Stream for Developers: A Practical Guide
- How to Replace a Game Controller Battery Safely
- Man-Sized 3D Printer? Why You Probably Don’t Need One100.0 cm³/h
- Scroll Horizontally with Mouse Wheel by Holding Shift5.00 min/km
- AI Competitor Monitoring Tools & Strategies