##// END OF EJS Templates
Merge pull request #6216 from SylvainCorlay/comm-unregister...
Min RK -
r17480:dc95bffe merge
parent child Browse files
Show More
@@ -56,9 +56,9 b' define(['
56 56 return comm.comm_id;
57 57 };
58 58
59 CommManager.prototype.unregister_comm = function (comm_id) {
59 CommManager.prototype.unregister_comm = function (comm) {
60 60 // Remove a comm from the mapping
61 delete this.comms[comm_id];
61 delete this.comms[comm.comm_id];
62 62 };
63 63
64 64 // comm message handlers
@@ -88,7 +88,7 b' define(['
88 88 if (comm === undefined) {
89 89 return;
90 90 }
91 delete this.comms[content.comm_id];
91 this.unregister_comm(comm);
92 92 try {
93 93 comm.handle_close(msg);
94 94 } catch (e) {
@@ -141,7 +141,6 b' class Widget(LoggingConfigurable):'
141 141 # Create a comm.
142 142 self._comm = Comm(target_name=self._model_name)
143 143 self._comm.on_msg(self._handle_msg)
144 self._comm.on_close(self._close)
145 144 Widget.widgets[self.model_id] = self
146 145
147 146 # first update
@@ -158,21 +157,18 b' class Widget(LoggingConfigurable):'
158 157 #-------------------------------------------------------------------------
159 158 # Methods
160 159 #-------------------------------------------------------------------------
161 def _close(self):
162 """Private close - cleanup objects, registry entries"""
163 del Widget.widgets[self.model_id]
164 self._comm = None
165 160
166 161 def close(self):
167 162 """Close method.
168 163
169 Closes the widget which closes the underlying comm.
164 Closes the underlying comm.
170 165 When the comm is closed, all of the widget views are automatically
171 166 removed from the front-end."""
167 del Widget.widgets[self.model_id]
172 168 if self._comm is not None:
173 169 self._comm.close()
174 self._close()
175
170 self._comm = None
171
176 172 def send_state(self, key=None):
177 173 """Sends the widget state, or a piece of it, to the front-end.
178 174
@@ -50,7 +50,6 b' class Comm(LoggingConfigurable):'
50 50 if target_name:
51 51 kwargs['target_name'] = target_name
52 52 super(Comm, self).__init__(**kwargs)
53 get_ipython().comm_manager.register_comm(self)
54 53 if self.primary:
55 54 # I am primary, open my peer.
56 55 self.open(data)
@@ -77,6 +76,8 b' class Comm(LoggingConfigurable):'
77 76 """Open the frontend-side version of this comm"""
78 77 if data is None:
79 78 data = self._open_data
79 self._closed = False
80 get_ipython().comm_manager.register_comm(self)
80 81 self._publish_msg('comm_open', data, metadata, target_name=self.target_name)
81 82
82 83 def close(self, data=None, metadata=None):
@@ -87,6 +88,7 b' class Comm(LoggingConfigurable):'
87 88 if data is None:
88 89 data = self._close_data
89 90 self._publish_msg('comm_close', data, metadata)
91 get_ipython().comm_manager.unregister_comm(self)
90 92 self._closed = True
91 93
92 94 def send(self, data=None, metadata=None):
@@ -72,11 +72,10 b' class CommManager(LoggingConfigurable):'
72 72 self.comms[comm_id] = comm
73 73 return comm_id
74 74
75 def unregister_comm(self, comm_id):
75 def unregister_comm(self, comm):
76 76 """Unregister a comm, and close its counterpart"""
77 77 # unlike get_comm, this should raise a KeyError
78 comm = self.comms.pop(comm_id)
79 comm.close()
78 comm = self.comms.pop(comm.comm_id)
80 79
81 80 def get_comm(self, comm_id):
82 81 """Get a comm with a particular id
@@ -110,13 +109,11 b' class CommManager(LoggingConfigurable):'
110 109 self.log.error("No such comm target registered: %s", target_name)
111 110 comm.close()
112 111 return
113 self.register_comm(comm)
114 112 try:
115 113 f(comm, msg)
116 114 except Exception:
117 115 self.log.error("Exception opening comm with target: %s", target_name, exc_info=True)
118 116 comm.close()
119 self.unregister_comm(comm_id)
120 117
121 118 def comm_msg(self, stream, ident, msg):
122 119 """Handler for comm_msg messages"""
General Comments 0
You need to be logged in to leave comments. Login now