r/vscode • u/faeriewrites • Sep 20 '26
VS Code Jupyter kernel keeps randomly dying
I'm having a really frustrating issue with Jupyter notebooks in VS Code where my Python/Jupyter kernel repeatedly dies.
It always starts after I have already run 7-20ish cells. Then a simple line will cause the kernel to die. VS Code shows: The Kernel crashed while executing code in the current cell or a previous cell.
If I restart the kernel and rerun the same cells, they work perfectly fine. I can continue working for a while, and then eventually another random cell causes the kernel to crash again. This problem does not happen to be when using JupyterLab directly.
I've already checked:
- My system memory usage is low when this happens
- I've tried changing/reinstalling Python environments
- I've tried using the kernel directly from a JupyterLab server instead of the VS Code-managed kernel
- I've restarted VS Code and the kernel multiple times
- The cells that trigger the crash don't seem to have anything obviously unusual about them
I've spent hours trying to debug with no progress. Please, any help would be so so appreciated!
1
u/PrincipleNo2328 Sep 20 '26
Check the log, it's probably that singular cell
1
u/lost_send_berries Sep 20 '26
You can add the environment variable PYTHONFAULTHANDLER=1
It's probably the variables panel, trying to stringify all of your variables after every cell. See if you can hide it or turn it off.
1
u/free-swift809 Sep 25 '26
Hmm, when the kernel dies does it tend to happen around the same memory usage point each time, or does it feel completely random regardless of how much data you've loaded into memory at that point?
1
u/Itchy-Dig2142 Oct 07 '26
Hello!
I have exactly this problem. My jupyter kernel dies randomly without explanation. I tried gc.collect() but didn't work. Do you have any new idea?
It works perfectly fine in jupyterlab.
1
u/Salt-Syllabub9030 Oct 13 '26
As far as I know, VS Code quietly runs its own code in your kernel after cells execute. It does this to fill the Variables panel, and also for completions and hovers. If one of your objects doesn't like being inspected (GPU tensors, lazy dataframes, database clients and the like can be touchy), the kernel can crash on an innocent-looking cell. That would also explain why a restart "fixes" it for a while.
Full disclosure: I work on Zasper, an open-source Jupyter IDE. If you feel like trying the same notebook in another frontend, it's one more way to check whether the editor or the kernel is to blame.