Skip to content

Conversation

@3coins
Copy link
Collaborator

@3coins 3coins commented Jun 12, 2025

Fixes #95

Sample code to test:

%pip install -q ipywidgets
from ipywidgets import Output
from IPython.display import display

out = Output()
display(out)
import time

with out:
    print("Hello!")

time.sleep(2)
out.clear_output(wait=True) # default is wait=False, which should clear the output immediately

time.sleep(2)
with out:
  print("Hello again!")

@3coins
Copy link
Collaborator Author

3coins commented Jun 12, 2025

@ellisonbg
This change behaves similar to what I see on the JLab v4.4.3 without jupter-server-documents, but after reading the documentation for Output widget I am a bit confused if this is correct. In the example code above, since the display(out) was in the 2nd cell, shouldn't the statements in cell 3 cause an update on cell 2 output (where the output widget is displayed) rather than cell 3?

@3coins 3coins marked this pull request as ready for review June 12, 2025 19:58
if target_cell is not None:
target_cell["outputs"].clear()
self.log.info(f"Cleared outputs for ydoc: {room_id} {cell_index}")
self.log.info(f"Cleared outputs for {self._file_id=}, {cell_index=}")
Copy link
Collaborator

@dlqqq dlqqq Jun 12, 2025

Choose a reason for hiding this comment

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

Copy link
Collaborator

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

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

@3coins Very cool, thanks! Tested this locally and it works well. Left some feedback on the code, but none of it is blocking since this works as-is. 👍

@3coins
Copy link
Collaborator Author

3coins commented Jun 13, 2025

@dlqqq
Thanks for all the feedback, updated and resolved all of your comments.

@ellisonbg
Copy link
Collaborator

Have you tried a non-widgets example:

from IPython.display import clear_output
import time

for i in range(5):
    print(f"Iteration: {i}")
    time.sleep(1)
    clear_output(wait=True)
print("Loop finished")

@3coins
Copy link
Collaborator Author

3coins commented Jun 13, 2025

@ellisonbg
Works the same way with non-widget example.

Screen.Recording.2025-06-13.at.9.46.36.AM.mov

Copy link
Collaborator

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@3coins 3coins merged commit dd042c6 into jupyter-ai-contrib:main Jun 16, 2025
4 of 6 checks passed
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.

Handle clear_output message

3 participants