Skip to content

Comms not cleared after re-executing cell with ipywidgets #3995

@bd-Kwasniewski

Description

@bd-Kwasniewski

When I re-execute a cell that creates an ipywidget (e.g., IntSlider), the old comm is not closed and remains in get_ipython().kernel.comm_manager.comms. This leads to multiple comms accumulating after repeated executions, even after clearing the cell output.

Reproduce

  1. execute in cell
import ipywidgets as widgets
from IPython.display import display

slider = widgets.IntSlider()
display(slider)
  1. execute in second cell
get_ipython().kernel.comm_manager.comms
  1. observe 3 comms present

  2. rexecute cell 1

  3. observe in cell 2 that 6 comms are present

Image

Expected behavior

Old comms should be closed when the cell output is cleared or replaced, so only one comm remains per widget.

Context

  • ipywidgets version 8.1.7
  • Operating System and version: macos 15.5
  • Browser and version: chrome 138.0.7204.169

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions