Jupyter notebook kernel keeps dying: DeadKernelError, crash vs out of memory (tested)
When a Jupyter kernel keeps dying, the Python process was killed or crashed, so there is no traceback: running out of memory (the OS kills it) and a crash in compiled code look exactly the same. Below both are reproduced, plus how a memory limit turns the death into a catchable MemoryError.
1. Reproduce: a crash, a hard kill, and a memory limit
run.sh builds three small notebooks and executes them headless with nbconvert, which reports a dead kernel as DeadKernelError (the Notebook/Lab UI shows its own "kernel died / restarting" notice for the same event). os.abort() stands in for a crashing C extension; SIGKILL is what the Linux out-of-memory killer sends.
cd /tmp/kd408
export PATH=/tmp/jn408/ve/bin:$PATH
mk() { python -c "
import json,sys
nb={'cells':[{'cell_type':'code','execution_count':None,'id':'c%d'%i,'metadata':{},'outputs':[],'source':[s]} for i,s in enumerate(sys.argv[2:])],
'metadata':{'kernelspec':{'name':'python3','display_name':'Python 3','language':'python'}},'nbformat':4,'nbformat_minor':5}
json.dump(nb,open(sys.argv[1],'w'))" "$@"; }
mk crash.ipynb "print('cell 1 ok')" "import os; os.abort() # stands in for a crashing C extension"
mk kill.ipynb "print('cell 1 ok')" "import os, signal; os.kill(os.getpid(), signal.SIGKILL) # what the Linux OOM killer does"
mk limit.ipynb "import resource; resource.setrlimit(resource.RLIMIT_AS, (1500 * 1024**2,) * 2)" "x = bytearray(3000 * 1024**2)" "print('kernel still alive')"
echo '$ jupyter nbconvert --to notebook --execute crash.ipynb'
jupyter nbconvert --to notebook --execute crash.ipynb 2>&1 | grep -E "DeadKernelError|Kernel died|^\[NbConvertApp\]" | head -3
echo
echo '$ jupyter nbconvert --to notebook --execute kill.ipynb'
jupyter nbconvert --to notebook --execute kill.ipynb 2>&1 | grep -E "DeadKernelError|Kernel died" | head -2
echo
echo '$ jupyter nbconvert --to notebook --execute --allow-errors --stdout limit.ipynb | grep -E "ename|kernel still"'
jupyter nbconvert --to notebook --execute --allow-errors --stdout limit.ipynb 2>/dev/null | grep -E '"ename"|kernel still alive\\n"$'
Output (nbconvert 7.17.2, ipykernel, Python 3.13 on Linux):
$ jupyter nbconvert --to notebook --execute crash.ipynb
[NbConvertApp] Converting notebook crash.ipynb to notebook
[NbConvertApp] ERROR | Kernel died while waiting for execute reply.
raise DeadKernelError("Kernel died") from None
$ jupyter nbconvert --to notebook --execute kill.ipynb
[NbConvertApp] ERROR | Kernel died while waiting for execute reply.
raise DeadKernelError("Kernel died") from None
$ jupyter nbconvert --to notebook --execute --allow-errors --stdout limit.ipynb | grep -E "ename|kernel still"
"ename": "MemoryError",
"kernel still alive\n"
- A native crash (abort/segfault in compiled code) and a hard kill look identical from Jupyter's side:
Kernel died while waiting for execute reply. There is no Python traceback, because the process is gone, so the message alone doesn't tell you which it was. - An out-of-memory kill gives no Python
MemoryError. When the process has a memory limit instead (resource.setrlimit(RLIMIT_AS, ...)at 1.5 GB inlimit.ipynb), the 3 GB allocation raisedMemoryErroras a normal exception and the next cell still ran: the kernel survived.
2. Finding the cause
- Memory: watch memory while the cell runs; on Linux check the system log (
dmesgorjournalctl -k) for an out-of-memory kill right after the death. Fix by loading less (chunks, smaller dtypes,delbig objects) or, as above, set a memory limit so you get a catchableMemoryErrorinstead of a dead kernel. - Native crash: run the same code as a plain script (
jupyter nbconvert --to script, thenpython -X faulthandler file.py) to see which line and library crashes; mismatched binary packages (e.g. two copies of a library from pip and conda, or a wheel built for another NumPy) are the usual suspects. Reinstall them in one environment. - Wrong environment: if the kernel dies right at startup, check
jupyter kernelspec listand the Python path in the kernel'skernel.json(see kernel not found).
Related: Jupyter "Error Starting Kernel", jupyter nbconvert is not installed.
Frequently asked questions
Why does my Jupyter kernel keep dying?
Usually the process runs out of memory and is killed by the OS, or a compiled library crashes. Both show "Kernel died" with no traceback.
How do I check if the Jupyter kernel died from out of memory?
Watch memory while the cell runs and check dmesg or journalctl -k for an out-of-memory kill right after the death.
What is DeadKernelError in nbconvert?
nbconvert's error when the kernel process exits while executing a cell: "Kernel died while waiting for execute reply".
Written with AI assistance. Measured on 2026-10-23 with nbconvert 7.17.2, ipykernel and Python 3.13 on Linux. The script ran verbatim and the output was pasted unedited. PlainTables is our extension; Jupyter is free.