Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Unsubscribe deleted plots from streams #2141
When you delete or clear a cell containing a HoloViews plot subscribed to streams in the notebook the plot instance sticks around and continues to be subscribed to Stream events, which can slow things down if you redisplay the same plot. This is a major annoyance that has caught me out frequently. It should be possible to keep track of which cell a plot was displayed in and delete it and unsubscribe from any streams the plot was attached to.
The relevant Jupyter.notebook machinery is this:
with other events being listed here. Every plot that uses streams would send back the cell id on initialization and whenever a cell is deleted we could send a message back across a dedicated comm to notify Python of the cell deletion.
I think something similar may be necessary for tidying up after a bokeh server session is closed.
I think this is a good idea though I would want to ensure a few things:
Until we support JupyterLab in other ways I do not think we should let this hold things up. The APIs exist in JupyterLab but without writing an extension there's no way we're going to make this work on both and that work will/should all happen in one chunk.
Can't see how it would ever break something, all the execution would be triggered on the JS end so if it fails, at worst nothing happens. Also these APIs have been stable since very early notebook versions <3.0
This would mostly be handled in the ipython extension, so I think it's perfectly reasonable to specifically handle cell ids, but some of the plot/stream cleanup can of course use general APIs, which will probably also be useful for lifecycle hooks on bokeh server.