diff --git a/IPython/html/static/services/kernels/js/comm.js b/IPython/html/static/services/kernels/js/comm.js
index 4cb24a6fa..04307cf40 100644
--- a/IPython/html/static/services/kernels/js/comm.js
+++ b/IPython/html/static/services/kernels/js/comm.js
@@ -56,9 +56,9 @@ define([
return comm.comm_id;
};
- CommManager.prototype.unregister_comm = function (comm_id) {
+ CommManager.prototype.unregister_comm = function (comm) {
// Remove a comm from the mapping
- delete this.comms[comm_id];
+ delete this.comms[comm.comm_id];
};
// comm message handlers
@@ -88,7 +88,7 @@ define([
if (comm === undefined) {
return;
}
- delete this.comms[content.comm_id];
+ this.unregister_comm(comm);
try {
comm.handle_close(msg);
} catch (e) {
diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py
index 345a4c7ec..745e7d60f 100644
--- a/IPython/html/widgets/widget.py
+++ b/IPython/html/widgets/widget.py
@@ -141,7 +141,6 @@ class Widget(LoggingConfigurable):
# Create a comm.
self._comm = Comm(target_name=self._model_name)
self._comm.on_msg(self._handle_msg)
- self._comm.on_close(self._close)
Widget.widgets[self.model_id] = self
# first update
@@ -158,21 +157,18 @@ class Widget(LoggingConfigurable):
#-------------------------------------------------------------------------
# Methods
#-------------------------------------------------------------------------
- def _close(self):
- """Private close - cleanup objects, registry entries"""
- del Widget.widgets[self.model_id]
- self._comm = None
def close(self):
"""Close method.
- Closes the widget which closes the underlying comm.
+ Closes the underlying comm.
When the comm is closed, all of the widget views are automatically
removed from the front-end."""
+ del Widget.widgets[self.model_id]
if self._comm is not None:
self._comm.close()
- self._close()
-
+ self._comm = None
+
def send_state(self, key=None):
"""Sends the widget state, or a piece of it, to the front-end.