Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions jupyter_rtc_core/outputs/output_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ def get_msg_id(self, cell_id):
"""Retrieve a msg_id from a cell_id."""
return {v: k for k, v in self._cell_ids.items()}.get(cell_id)

async def clear_cell_outputs(self, cell_id, room_id):
"""Clears the outputs of a cell in ydoc"""
room = self.yroom_manager.get_room(room_id)
if room is None:
self.log.error(f"YRoom not found: {room_id}")
return
notebook = await room.get_jupyter_ydoc()
self.log.info(f"Notebook: {notebook}")

cells = notebook.ycells
cell_index, target_cell = self.find_cell(cell_id, cells)
if target_cell is not None:
target_cell["outputs"].clear()
self.log.info(f"Cleared outputs for ydoc: {room_id} {cell_index}")


# Incoming messages

def process_incoming_message(self, channel: str, msg: list[bytes]):
Expand Down Expand Up @@ -106,6 +122,8 @@ def process_incoming_message(self, channel: str, msg: list[bytes]):
self.clear(cell_id)
if self._file_id is not None:
if self.use_outputs_service:
room_id = f"json:notebook:{self._file_id}"
asyncio.create_task(self.clear_cell_outputs(cell_id, room_id))
self.outputs_manager.clear(file_id=self._file_id, cell_id=cell_id)
self.outputs_manager.clear(file_id=self._file_id)
self.log.info(f"Saving (msg_id, cell_id): ({msg_id} {cell_id})")
Expand Down
Loading