Skip to content

Labmanager refactor #2532

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

Merged
merged 9 commits into from
Jan 17, 2020
Merged

Conversation

vidartf
Copy link
Member

@vidartf vidartf commented Aug 13, 2019

This PR builds on top of #2528.

What does this do?
Extract parts of the widget manager into an abstract base class, and then export a new widget manager that does not rely on the document context. Instead, it takes a kernel as an argument to the constructor.

What is the purpose?
The goal of this PR is to make it easier for others to reuse widgets in a setting outside of Jupyterlab, (but while still using Jupyterlab components as libraries).

Does this really belong in this package?
Ideally, the base and kernel-based manager could live in a new, separate package, but I don't want to increase the maintenance burden of the repo/releases any more, so I think it would probably be better to later on optimize the current package for tree-shaking.

@vidartf
Copy link
Member Author

vidartf commented Aug 13, 2019

For reference, here is the diff of this PR onto #2528: vidartf/ipywidgets@lab-optionals...vidartf:labmanager-refactor

@jasongrout
Copy link
Member

jasongrout commented Jan 11, 2020

Needs a rebase (and at least some of this is incorporated in other PRs like #2707)

Extract parts of the widget manager into an abstract base class, and then export a new widget manager that does not rely on the document context. Instead, it takes a kernel as an argument to the constructor.
@vidartf vidartf force-pushed the labmanager-refactor branch from 729aaf9 to 9d999d7 Compare January 15, 2020 01:02
@vidartf
Copy link
Member Author

vidartf commented Jan 15, 2020

Rebased, but will need a careful review, as I'm not sure I caught all the nuances with the new services API.

@jasongrout
Copy link
Member

@vidartf, I took a look at this today. I pushed a few commits cleaning up a few things. If those look good to you, then I think we can merge this.

@jasongrout jasongrout added this to the 8.0 milestone Jan 15, 2020
Right now in JupyterLab, if you create and display a widget in a notebook, then refresh the page, the widget is replaced with a “could not find model” error message.

This is because the initial kernel widget restore is called before the widget manager has a kernel, so the kernel restore silently fails and the widget manager thinks it has restored things. Then when we try to render the widgets, we give up too soon, thinking that we have already restored any existing widget state.

This change makes it so that the widget manager recognizes that the initial restore attempt did happen (even if it didn’t actually get anything from the kernel because the kernel was not set), but the manager also realizes that the kernel restore did *not* happen. Then when the kernel is set, the kernel connected signal triggers another restore, which can then complete the widget manager restoration.
… natural

Instead of just an initial state restore, this makes it so that we never ask for a kernel restore when another kernel restore is already in progress. A subcase of this is the initial restore race logic from the previous commit.
@jasongrout
Copy link
Member

I also fixed a race condition that has been bothering us since updating to JLab 2.0. CC @wolfv.

@jasongrout
Copy link
Member

@vidartf, do you want to take a look at this again?

Copy link
Member Author

@vidartf vidartf left a comment

Choose a reason for hiding this comment

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

Adding off-topic commits is a little annoying, but I see why it is expedient. Lets merge and iterate on it (comments for consideration for a follow-up).

this._initialRestoredStatus = true;
this._restored.emit();
} catch (err) {
// Do nothing
Copy link
Member Author

Choose a reason for hiding this comment

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

This shouldn't really happen for the KernelWidgetManager, but I agree with being defensive.

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean there won't be an error in loading from kernel in the widget manager? We aren't throwing one explicitly, but of course there could be one, and that would leave us in a weird state for the flag, so I think it's important to be defensive.

Probably even better semantically to have it in a finally statement, though.

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe even better to move the flag setting into _loadFromKernel...

await this._loadFromKernel();
} finally {
this._kernelRestoreInProgress = false;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Would it make more sense to put the setting/unsetting of this flag inside the method?

Copy link
Member

Choose a reason for hiding this comment

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

Can you be more explicit about what you have in mind?

@vidartf vidartf merged commit 7cb20cd into jupyter-widgets:master Jan 17, 2020
@vidartf vidartf deleted the labmanager-refactor branch January 17, 2020 11:12
@jasongrout
Copy link
Member

Adding off-topic commits is a little annoying, but I see why it is expedient. Lets merge and iterate on it (comments for consideration for a follow-up).

I assume you are talking about the last two commits that fix a serious bug. If I would have made them in a different PR, I would have had to redo them anyway, so it only made sense to make them in the context of this PR. Thanks for the seeing the expediency.

@lock lock bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label May 20, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants