From a9c34b679bad3deedb9dc2317e443b40489f7707 Mon Sep 17 00:00:00 2001 From: "sylvain.corlay" Date: Sat, 26 Jul 2014 12:36:21 -0400 Subject: [PATCH 1/4] decoupling the comm lifetime from the widget lifetime --- IPython/html/widgets/widget.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index 345a4c7ec..3d1df8408 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -127,6 +127,8 @@ class Widget(LoggingConfigurable): def __del__(self): """Object disposal""" self.close() + del Widget.widgets[self.model_id] + self._comm = None #------------------------------------------------------------------------- # Properties @@ -141,7 +143,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,20 +159,15 @@ 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.""" if self._comm is not None: self._comm.close() - self._close() def send_state(self, key=None): """Sends the widget state, or a piece of it, to the front-end. From 2c648fe4d09dfeda6ae007f3725c3b4f44172bcc Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Tue, 29 Jul 2014 20:11:34 +0000 Subject: [PATCH 2/4] bad call and missing call to unregister_comm --- IPython/html/static/services/kernels/js/comm.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) { From ea52ef870475883ec108767d8f183b8f9afaedb1 Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Wed, 30 Jul 2014 00:28:30 +0000 Subject: [PATCH 3/4] del Widget.widgets[seld.model_id] in close rather than in __del__ --- IPython/html/widgets/widget.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index 3d1df8408..3a72d0de1 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -127,8 +127,6 @@ class Widget(LoggingConfigurable): def __del__(self): """Object disposal""" self.close() - del Widget.widgets[self.model_id] - self._comm = None #------------------------------------------------------------------------- # Properties @@ -166,9 +164,10 @@ class Widget(LoggingConfigurable): 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() - + def send_state(self, key=None): """Sends the widget state, or a piece of it, to the front-end. From 1bbc915ac0b0ff6b24d7655c9d48dfdd3392ffd0 Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Wed, 30 Jul 2014 23:16:24 -0400 Subject: [PATCH 4/4] setting _comm to None --- IPython/html/widgets/widget.py | 1 + 1 file changed, 1 insertion(+) diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index 3a72d0de1..745e7d60f 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -167,6 +167,7 @@ class Widget(LoggingConfigurable): del Widget.widgets[self.model_id] if self._comm is not None: self._comm.close() + self._comm = None def send_state(self, key=None): """Sends the widget state, or a piece of it, to the front-end.