Show More
@@ -49,7 +49,7 b' var IPython = (function (IPython) {' | |||||
49 | // Unregister a target function for a given target name |
|
49 | // Unregister a target function for a given target name | |
50 | delete this.targets[target_name]; |
|
50 | delete this.targets[target_name]; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | CommManager.prototype.register_comm = function (comm) { |
|
53 | CommManager.prototype.register_comm = function (comm) { | |
54 | // Register a comm in the mapping |
|
54 | // Register a comm in the mapping | |
55 | this.comms[comm.comm_id] = comm; |
|
55 | this.comms[comm.comm_id] = comm; | |
@@ -74,7 +74,13 b' var IPython = (function (IPython) {' | |||||
74 | } |
|
74 | } | |
75 | var comm = new Comm(content.comm_id); |
|
75 | var comm = new Comm(content.comm_id); | |
76 | this.register_comm(comm); |
|
76 | this.register_comm(comm); | |
77 | f(comm, msg); |
|
77 | try { | |
|
78 | f(comm, msg); | |||
|
79 | } catch (e) { | |||
|
80 | console.log("Exception opening new comm:", e, msg); | |||
|
81 | comm.close(); | |||
|
82 | this.unregister_comm(comm); | |||
|
83 | } | |||
78 | }; |
|
84 | }; | |
79 |
|
85 | |||
80 | CommManager.prototype.comm_close = function (msg) { |
|
86 | CommManager.prototype.comm_close = function (msg) { | |
@@ -84,7 +90,11 b' var IPython = (function (IPython) {' | |||||
84 | return; |
|
90 | return; | |
85 | } |
|
91 | } | |
86 | delete this.comms[content.comm_id]; |
|
92 | delete this.comms[content.comm_id]; | |
87 | comm.handle_close(msg); |
|
93 | try { | |
|
94 | comm.handle_close(msg); | |||
|
95 | } catch (e) { | |||
|
96 | console.log("Exception closing comm: ", e, msg); | |||
|
97 | } | |||
88 | }; |
|
98 | }; | |
89 |
|
99 | |||
90 | CommManager.prototype.comm_msg = function (msg) { |
|
100 | CommManager.prototype.comm_msg = function (msg) { | |
@@ -93,7 +103,11 b' var IPython = (function (IPython) {' | |||||
93 | if (comm === undefined) { |
|
103 | if (comm === undefined) { | |
94 | return; |
|
104 | return; | |
95 | } |
|
105 | } | |
96 | comm.handle_msg(msg); |
|
106 | try { | |
|
107 | comm.handle_msg(msg); | |||
|
108 | } catch (e) { | |||
|
109 | console.log("Exception handling comm msg: ", e, msg); | |||
|
110 | } | |||
97 | }; |
|
111 | }; | |
98 |
|
112 | |||
99 | //----------------------------------------------------------------------- |
|
113 | //----------------------------------------------------------------------- |
@@ -79,8 +79,10 b' class CommManager(LoggingConfigurable):' | |||||
79 | def register_target(self, target_name, f): |
|
79 | def register_target(self, target_name, f): | |
80 | """Register a callable f for a given target name |
|
80 | """Register a callable f for a given target name | |
81 |
|
81 | |||
82 | f will be called with a Comm object as its only argument |
|
82 | f will be called with two arguments when a comm_open message is received with `target`: | |
83 | when a comm_open message is received with `target`. |
|
83 | ||
|
84 | - the Comm instance | |||
|
85 | - the `comm_open` message itself. | |||
84 |
|
86 | |||
85 | f can be a Python callable or an import string for one. |
|
87 | f can be a Python callable or an import string for one. | |
86 | """ |
|
88 | """ | |
@@ -92,7 +94,7 b' class CommManager(LoggingConfigurable):' | |||||
92 | def unregister_target(self, target_name, f): |
|
94 | def unregister_target(self, target_name, f): | |
93 | """Unregister a callable registered with register_target""" |
|
95 | """Unregister a callable registered with register_target""" | |
94 | return self.targets.pop(target_name); |
|
96 | return self.targets.pop(target_name); | |
95 |
|
97 | |||
96 | def register_comm(self, comm): |
|
98 | def register_comm(self, comm): | |
97 | """Register a new comm""" |
|
99 | """Register a new comm""" | |
98 | comm_id = comm.comm_id |
|
100 | comm_id = comm.comm_id | |
@@ -141,7 +143,12 b' class CommManager(LoggingConfigurable):' | |||||
141 | comm.close() |
|
143 | comm.close() | |
142 | return |
|
144 | return | |
143 | self.register_comm(comm) |
|
145 | self.register_comm(comm) | |
144 | f(comm, msg) |
|
146 | try: | |
|
147 | f(comm, msg) | |||
|
148 | except Exception: | |||
|
149 | self.log.error("Exception opening comm with target: %s", target_name, exc_info=True) | |||
|
150 | comm.close() | |||
|
151 | self.unregister_comm(comm_id) | |||
145 |
|
152 | |||
146 | @with_output |
|
153 | @with_output | |
147 | def comm_msg(self, stream, ident, msg): |
|
154 | def comm_msg(self, stream, ident, msg): | |
@@ -152,7 +159,10 b' class CommManager(LoggingConfigurable):' | |||||
152 | if comm is None: |
|
159 | if comm is None: | |
153 | # no such comm |
|
160 | # no such comm | |
154 | return |
|
161 | return | |
155 | comm.handle_msg(msg) |
|
162 | try: | |
|
163 | comm.handle_msg(msg) | |||
|
164 | except Exception: | |||
|
165 | self.log.error("Exception in comm_msg for %s", comm_id, exc_info=True) | |||
156 |
|
166 | |||
157 | @with_output |
|
167 | @with_output | |
158 | def comm_close(self, stream, ident, msg): |
|
168 | def comm_close(self, stream, ident, msg): | |
@@ -162,9 +172,14 b' class CommManager(LoggingConfigurable):' | |||||
162 | comm = self.get_comm(comm_id) |
|
172 | comm = self.get_comm(comm_id) | |
163 | if comm is None: |
|
173 | if comm is None: | |
164 | # no such comm |
|
174 | # no such comm | |
|
175 | self.log.debug("No such comm to close: %s", comm_id) | |||
165 | return |
|
176 | return | |
166 | del self.comms[comm_id] |
|
177 | del self.comms[comm_id] | |
167 | comm.handle_close(msg) |
|
178 | ||
|
179 | try: | |||
|
180 | comm.handle_close(msg) | |||
|
181 | except Exception: | |||
|
182 | self.log.error("Exception handling comm_close for %s", comm_id, exc_info=True) | |||
168 |
|
183 | |||
169 |
|
184 | |||
170 | __all__ = ['CommManager'] |
|
185 | __all__ = ['CommManager'] |
General Comments 0
You need to be logged in to leave comments.
Login now