Skip to content

Isolate Bokeh state for concurrent plot output - #1423

Open
DirkEmmett wants to merge 1 commit into
kernc:masterfrom
DirkEmmett:fix/125-isolate-plot-state
Open

DirkEmmett wants to merge 1 commit into
kernc:masterfrom
DirkEmmett:fix/125-isolate-plot-state

Conversation

@DirkEmmett

Copy link
Copy Markdown

Concurrent plots share Bokeh's global output state, so one request can overwrite another request's HTML file or leave it missing.

Use per-call state and documents for plots and heatmaps, preserving notebook callbacks and delayed BokehJS loading.

Fixes #125.

Validation: 85 tests passed, 1 skipped on both Bokeh 3.10.1 and 3.1.1; the 3.10.1 browser smoke passed. Existing Mypy errors and the 3.1.1 browser-smoke failure also reproduce on the base revision.

Address kernc#125 with per-call documents and output state for plots and heatmaps. Preserve notebook callback isolation and native BokehJS loading, and cover concurrent files, output modes, and delayed notebook rendering.
@arhancanli

Copy link
Copy Markdown

Read the diff. I did not run the tests; I only checked what I could outside the suite.

The notebook branch of _show re-implements part of Bokeh's show_doc() with four non-public imports: bokeh.core.json_encoder.serialize_json, bokeh.core.templates.DOC_NB_JS, bokeh.embed.elements.div_for_render_item and bokeh.embed.util.standalone_docs_json_and_render_items. I downloaded the wheels and all four are present in Bokeh 3.1.1, 3.3.4 and 3.4.3 (the only versions I could fetch with Python 3.9), plus 3.10.1 per the PR's own run. That covers the two ends of the range setup.py allows (bokeh >= 3.0.0, != 3.0.*, != 3.2.*) but not 3.5 to 3.9, and the PR's validation names only 3.1.1 and 3.10.1. Since these are internals that Bokeh may move, a CI cell for one version in the middle would show early if one of them goes, and a comment in _show pointing at show_doc as the thing being mirrored would help whoever has to repair it.

The file path (save(fig, state=state) on a fresh State() per call) is the part that fixes #125, and test_concurrent_plot_files exercises it with a barrier inside gridplot, which forces the two calls to overlap. That is a good way to test it.

This branch has not been deployed

No deployments
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.

Backtest/Plot are not thread safe ?

2 participants