Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Single widget manager per kernel #3920

Conversation

fleming79
Copy link

This PR is exploring the possibility of a per-kernel widget manager as suggested by @jasongrout in the comments of the recently merged PR: #3004.

This PR follows on from a recent PR #3893, but could be easily re-based independently.

In it's current form, it can render the same widget in notebook[s] and consoles connected to the same kernel. The only requirement being that the KernelWidgetManager is registered to (instantiated with) the kernel.

image

How it works

KernelWidgetManager was modified to create only one instance per kernel.id.
WidgetManager was changed to be an interface for notebooks that swaps the notebook (panel) rendermime factory to use the KernelWidgetManager corresponding to the new kernel as the kernel is changed.

Other changes

  • WidgetRenderer was modified to search for the widget manager of a model_id if the widgetManager wasn't specified.
  • A timeout was added to ManagerBase.get_model which help avoid 'model not found' errors that occur when the view tries to render before the model promise has been created.
  • The plugin system was also modified to make it easier to create a KernelWidgetManager for a kernel that doesn't have a notebook attached (downstream use).

Alan Fleming and others added 30 commits March 10, 2024 09:50
…dentify closed widgets.

Added a new class `Children` for the children trait of Box optimised for checking widgets
and quietly dropping widgets that are closed, and objects that aren't widgets. Widgets in Box.children
 are also removed when the widget is closed.
 Added tests test_gc_box & test_gc_box_advanced
…pr_mimebundle_ is set to None when closed, this reduces the risk of name clash with subclasses.

Changed Children to allow any object that has the method `_repr_mimebundle_`.
Moved box related tests to test_widget_box.
Added `close` method to Box to ensure discarded children are un-observed.
…rgument `observe_children`.

Updated TestBox.
- change evaluation order to check for a widget first (most common object).
- raise NotImplementedError for objects with _repr_mimebundle_ that aren't widgets.
Fix 'Exception' for a Box that has been provided a tooltip.
Copy link

Binder 👈 Launch a binder notebook on branch fleming79/ipywidgets/single-widget-manager-per-kernel

@fleming79 fleming79 closed this May 25, 2024
@martinRenou
Copy link
Member

Thanks for opening a PR for this! Was this closed on purpose?

@fleming79
Copy link
Author

Yes and no.

If there is still the possibility of a per-kernel widget manager I can re-open or make a new PR with updates.

@martinRenou
Copy link
Member

I believe we're still open to refactor the widget manager logic to be more "general" and less tight to the Notebook (or the console). #3004 was merged as-is because it's already an improvement of the current state, but Jason's comments in the PR are still relevant.

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