Symptom
A Python notebook cell or job task fails with:
Fatal error: The Python kernel is unresponsive.
Sometimes it is followed by "The Python process exited with exit code 137" or a note that the REPL was restarted. Variables defined earlier in the notebook are gone. The cluster itself usually stays up, which is how this differs from "driver is temporarily unavailable".
The Python process on the driver died or stopped answering health checks. There are three common reasons, in this order of likelihood:
| Cause | Typical evidence | Fix |
|---|---|---|
| Driver ran out of memory | Driver memory near 100% in metrics, exit code 137, toPandas(), collect() or large pandas work in the failing cell | Keep data in Spark, shrink results, bigger driver |
| Too many notebooks or jobs on one all-purpose cluster | Fails at random cells, worse at busy times, several users attached | Move jobs to job compute, split users |
| Native library crash (segfault) | Fails instantly on import or one specific call, every time | Fix or replace the library (headless builds, matching versions) |
Checks
1. Look at driver memory at the time of the failure
On the cluster page open Metrics and select the driver. A sawtooth climbing to the limit right before the error is a memory problem.
For past failures, query the node timeline (requires access to system.compute):
SELECT start_time, cpu_user_percent, mem_used_percent, mem_swap_percent
FROM system.compute.node_timeline
WHERE cluster_id = '<cluster-id>'
AND driver = true
AND start_time BETWEEN '<failure time - 30 min>' AND '<failure time + 5 min>'
ORDER BY start_time;
mem_used_percent in the high 90s or any meaningful swap before the failure points to memory.
2. Read the driver logs
Cluster page, Driver logs: check stderr and stdout around the failure time. Look for:
Killed,MemoryErroror exit code 137: the process was killed for memory.Segmentation fault,Fatal Python error,core dumped: native crash in a C extension.- Repeated "Python REPL" restart messages for different notebooks: shared-cluster pressure.
If you configured cluster log delivery, the same files are under <log destination>/<cluster-id>/driver/.
3. Check cluster events
databricks clusters events <cluster-id> --output json | \
jq -r '.[] | [(.timestamp/1000 | todate), .type, (.details.reason.code // "")] | @tsv' | head -40
Events such as DRIVER_NOT_RESPONDING or DRIVER_UNAVAILABLE near the failure mean the whole driver was under pressure, not just one notebook. Event names vary by version; check your output.
4. Count what else was running on the driver
On an all-purpose cluster, every attached notebook has its own Python process on the same driver VM. Check the cluster's Notebooks tab (or attached notebooks in the cluster UI) and the job runs that used the cluster:
SELECT job_id, run_id, period_start_time, period_end_time, result_state
FROM system.lakeflow.job_task_run_timeline
WHERE array_contains(compute_ids, '<cluster-id>')
AND period_start_time > now() - INTERVAL 1 DAY
ORDER BY period_start_time DESC;
Several scheduled jobs plus interactive users on one cluster is the pattern the Databricks KB calls out for this error.
5. Reproduce the native-crash case
If the failure happens immediately and every time on the same line, run it in a fresh Python process with faulthandler so you get a Python traceback in stderr when it segfaults:
import faulthandler, sys
faulthandler.enable(file=sys.stderr)
import cv2 # or the suspect library / call
Then check package versions that commonly clash:
from importlib.metadata import distributions
for d in sorted(distributions(), key=lambda d: d.metadata["Name"].lower()):
if any(k in d.metadata["Name"].lower() for k in ["numpy", "pandas", "pyarrow", "opencv", "torch", "protobuf"]):
print(d.metadata["Name"], d.version)
Fixes
Driver memory
Keep large data in Spark and bring only small results to the driver:
# Instead of this on a large table:
pdf = spark.table("main.sales.orders").toPandas()
# Aggregate or filter in Spark first, then convert a small result
summary = (spark.table("main.sales.orders")
.groupBy("region").agg({"amount": "sum"}))
pdf = summary.toPandas()
# Need a sample for exploration? Limit it explicitly
sample = spark.table("main.sales.orders").limit(100_000).toPandas()
Other fixes:
- Write results to a table or volume instead of
collect()and Python loops. - Use pandas UDFs or the pandas API on Spark so pandas work runs on executors, not the driver.
- Release memory in long notebooks:
del big_dfthenimport gc; gc.collect(), or restart Python withdbutils.library.restartPython(). - Choose a memory-optimized or larger driver: set
driver_node_type_idindependently from workers. Driver-heavy jobs rarely need large workers too. spark.driver.maxResultSizelimits results sent to the driver. Raising it hides the problem and can make the crash more likely; prefer reducing the result.
Warning
Restarting Python or the cluster clears all notebook state for every user attached to it. On a shared all-purpose cluster, tell the other users first or restart only your own Python process with
dbutils.library.restartPython().
Shared cluster pressure
- Move scheduled work to job compute or serverless jobs. Each job then gets its own driver, and an interactive user's
toPandas()can no longer kill a production task. - Split heavy interactive users onto their own clusters, or use a compute policy that limits how many users share one.
- Stop attaching ad hoc notebooks to clusters that run production jobs.
Native library crashes
opencv-pythonneeds GUI libraries that are not on a headless cluster. Installopencv-python-headlessinstead and restart Python.- Pin versions that match the runtime. Installing a different
numpyorpyarrowthan the one the Databricks Runtime ships can break compiled extensions. Check the runtime release notes for preinstalled versions and pin compatible ones in a requirements file. - Install libraries at cluster or job level (or in an environment for serverless) instead of
%pip installmidway through a notebook, so every run gets the same set. - If a library needs OS packages, install them in an init script or a custom container image, then test on a single-node cluster.
Verify
Rerun the job on clean compute and watch driver memory in the Metrics tab during the failing cell. A healthy run keeps headroom on the driver and shows no Python restarts in stderr.
Prevent it next time
- Production jobs run on job compute or serverless, never on shared all-purpose clusters.
- Code review rule: no
toPandas()orcollect()on unbounded tables; require a filter, aggregate orlimit. - Pin library versions per job and upgrade them with the runtime, not separately.
- Enable cluster log delivery so driver
stderrsurvives cluster termination. - Alert on repeated failures of the same task (see the job alerts post) so a creeping memory problem is seen before it becomes a daily failure.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get