Skip to content

Explain figure rendering failures caused by kernel subshells - #597

Merged
SimonHeybrock merged 3 commits into
mainfrom
596-explain-subshell-concurrency
Aug 3, 2026
Merged

Explain figure rendering failures caused by kernel subshells#597
SimonHeybrock merged 3 commits into
mainfrom
596-explain-subshell-concurrency

Conversation

@SimonHeybrock

@SimonHeybrock SimonHeybrock commented Jul 31, 2026

Copy link
Copy Markdown
Member

Documents the JupyterLab subshell concurrency problem and its workarounds next to the installation instructions. Gives #596 the only answer plopp can give, and #499 a user-visible one.

JupyterLab >= 4.4 defaults to routing widget comm messages over kernel subshells, which ipykernel >= 7 services on their own threads. ipympl canvas draw/resize requests are then handled concurrently with cell execution, and Matplotlib is not thread-safe: a live canvas racing a figure build corrupts shared state. Symptoms are math text parse errors, blank figures, and kernel crashes, none of which point anywhere actionable. See ipympl#610 for the analysis.

There is no fix on our side. ipympl#621 locks Matplotlib's math text parser, which removes the parse errors, but the blank figures and crashes survive it: the frame path (get_diff_image reading buffer_rgba()) and handle_resize still run on the comm thread with no lockable API. Setting commsOverSubshells to disabled or pinning ipykernel<7 are the only workarounds verified to be fully stable, so those are what we document.

An earlier version of this branch also chained the failure into an explanatory error at figure creation. That is dropped: it hooked the math text exception, which is exactly the symptom the ipympl lock removes, while what survives the lock raises nothing to hook.

Test plan

  • Docs build renders the new section.

JupyterLab >= 4.4 routes widget messages over kernel subshells, which
ipykernel >= 7 services on their own threads. Drawing a live canvas then
races with figure creation during cell execution, and Matplotlib is not
thread-safe. The resulting mathtext parse error gives users no hint of
the cause or of the available workarounds.

When laying out a canvas fails while subshells are active, chain the
original error into one that names the cause and both workarounds, and
document them alongside the installation instructions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@nvaytet

nvaytet commented Jul 31, 2026

Copy link
Copy Markdown
Member

See also matplotlib/ipympl#621

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have my reservations as to how useful these tests are. We are trying to make a workaround for an issue that we hope will be fixed upstream.

Creating these fakes that mimic some private or undocumented properties of ipykernel feels like they could get out of date without us noticing.
We are also faking the error from the canvas, so the tests seem quite remote from the actual behaviour?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try monkey-patching as in the PR you linked instead?

The runtime detection hooked the math text ParseException raised during
tight_layout. That symptom is the one an ipympl-side parser lock removes;
what survives the lock -- blank canvases and kernel crashes -- raises no
exception, so the detection would catch nothing once ipympl releases.

The workarounds are unchanged and remain the only complete fix, so keep
them documented next to the installation instructions.
@SimonHeybrock
SimonHeybrock merged commit e7c18a8 into main Aug 3, 2026
5 checks passed
@SimonHeybrock
SimonHeybrock deleted the 596-explain-subshell-concurrency branch August 3, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants