-
Notifications
You must be signed in to change notification settings - Fork 948
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
Question: append_stdout and output widgets -- bad complexity? #2385
Comments
Yes, quite possibly if you are doing something huge.
No.
This is a problem with the simple syncing protocol for this outputs array - we sync the full array every time. If you do a clear using the method on the widget, it should clear the array. If you do a clear using the clear_output() function, the clearing happens on the client and we run into issues with messages crossing between the client and kernel. |
I've thought a little about how to do proper append-only syncing for ipywidgets attributes (or in general some sort of diff-based syncing), which would also be useful for streaming sources like browser cameras or audio. I (and others) haven't thought about it enough to sit down and figure it out, though. |
I understand -- I just wanted to make sure I wasn't missing something in the protocol.
In CoCalc I have the same problem with diffing arrays, which I haven't got around to adding to the protocol (I just record the whole array in the diff). However, I have much better diffing of Maps (just send the changed key/values), so I use maps (with "integer" keys) instead of arrays for output, thus avoiding the problem. The main thing you have to watch out for is that all map keys are actually strings in Javascript, and of course the JSON representation is a tiny bit less efficient.
That's useful. By "the widget" you mean the frontend widget in the browser? Basically, you're saying that there is some comm message the frontend widget can send the kernel, which will actually clear that array? And, if one calls |
Maybe this PR is useful: |
William, the front end should just sync an empty outputs array...that's the comm message. |
Got it. So it sends a message updating the value to be empty. I'll try that. Oh, and @maartenbreddels code makes that very clear. |
Yes. Here is the code in the classic notebook output widget doing that: ipywidgets/widgetsnbextension/src/widget_output.js Lines 45 to 48 in f78dcb6
|
Note that code is actually wrong I believe, assuming https://github.com/jupyter-widgets/ipywidgets/pull/2351/files is correct, it does not respect wait=True. A similar fix was done for nbconvert here: https://github.com/jupyter/nbconvert/pull/969/files Hope that helps to clarify things. |
Thanks for the all the help everybody. With that, it was pretty easy to implement clear_output, and here's what I came up with for CoCalc: |
Closing as answered. |
CC also the other output widget discussion from William, which contains a few more insights into the output widget design decisions: #2377 |
Suppose you run the following code:
Then some of the IOPUB messages look like this:
and
and finally
QUESTION: Ok that works, but what if you did
as you could easily imagine someone doing. Isn't this going to blow up in your face? Am I missing something? Even if you do clears, every IOPUB message contains the full history.
Just curious.
The text was updated successfully, but these errors were encountered: