-
Notifications
You must be signed in to change notification settings - Fork 44
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
save_changes
does not correctly synchronize to python-side
#788
Comments
Update: I confirmed that using e.g. traitlets @observe("values")
def _observe_values(self, change):
print(f"Old: {change['old']}")
print(f"New: {change['new']}") This only triggers when |
This behavior is expected due to how Jupyter widgets synchronize state between Python and the frontend. There is two-way data binding, but synchronization between JS <> Python happens asynchronously, meaning there is no built-in way to block Python execution while waiting for a response from the frontend. In your snippet, Some anywidget developers have found |
@manzt Ahh I see, I suspected it may be an async-related issue but I figured I'd ask because I actually had no idea if-or-how Python's async interacts with JS async. Thanks for the explanation and the links too, I see now that this is effectively a duplicate of #54. Closing as a result. In the meantime, I'm just going to get more clever with when the synchronizations happen. |
Of course! Thanks for the clear and detailed issue. We should probably have a section in the docs detailing this as it comes up from time to time on the Discord too.
If you find any patterns that work well, please share! |
Describe the bug
As far as I can tell, one cannot actually do "two-way data binding" via synchronizing traitlet-managed data, as
save_changes
doesn't appear to actually work (at least synchronously...)This might be a duplicate of #786, but the example is much smaller.
Reproduction
Firstly, a minimal widget that defines a supposedly synchronized List traitlet and a custom message to sync:
On jupyter, setting this value works as intended:
The issue is the synchronization doesn't work, at least programmatically:
Now, if you wait for about a second or so in the browser and then re-execute the getter for
widget.values
, you get the following:Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: