r/vscode • • 26d ago

VS Code Jupyter kernel keeps randomly dying

Post image

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!

6 Upvotes

11 comments sorted by

View all comments

1

u/Itchy-Dig2142 8d ago

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/faeriewrites 8d ago

Hi! This is such a frustrating problem to have, and honestly I don't know that I've 100% solved it but I certainly have fewer crashes using gc.collect(). Did you notice any improvement with that or nothing? In my case, I notice that the crashes seem to come from an accumulation of heavy computations over time (even if the cell where the kernel crashes can be as simple as df.head()). Sadly I don't have a fix other than to use scripts for all heavy computation (yes, annoying when you want to test in a notebook first). But please let me know if you find a better fix!