Show More
@@ -49,7 +49,7 b' var IPython = (function (IPython) {' | |||
|
49 | 49 | // Unregister a target function for a given target name |
|
50 | 50 | delete this.targets[target_name]; |
|
51 | 51 | }; |
|
52 | ||
|
52 | ||
|
53 | 53 | CommManager.prototype.register_comm = function (comm) { |
|
54 | 54 | // Register a comm in the mapping |
|
55 | 55 | this.comms[comm.comm_id] = comm; |
@@ -74,7 +74,13 b' var IPython = (function (IPython) {' | |||
|
74 | 74 | } |
|
75 | 75 | var comm = new Comm(content.comm_id); |
|
76 | 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 | 86 | CommManager.prototype.comm_close = function (msg) { |
@@ -84,7 +90,11 b' var IPython = (function (IPython) {' | |||
|
84 | 90 | return; |
|
85 | 91 | } |
|
86 | 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 | 100 | CommManager.prototype.comm_msg = function (msg) { |
@@ -93,7 +103,11 b' var IPython = (function (IPython) {' | |||
|
93 | 103 | if (comm === undefined) { |
|
94 | 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 | 79 | def register_target(self, target_name, f): |
|
80 | 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 | |
|
83 | when a comm_open message is received with `target`. | |
|
82 | f will be called with two arguments when a comm_open message is received with `target`: | |
|
83 | ||
|
84 | - the Comm instance | |
|
85 | - the `comm_open` message itself. | |
|
84 | 86 | |
|
85 | 87 | f can be a Python callable or an import string for one. |
|
86 | 88 | """ |
@@ -92,7 +94,7 b' class CommManager(LoggingConfigurable):' | |||
|
92 | 94 | def unregister_target(self, target_name, f): |
|
93 | 95 | """Unregister a callable registered with register_target""" |
|
94 | 96 | return self.targets.pop(target_name); |
|
95 | ||
|
97 | ||
|
96 | 98 | def register_comm(self, comm): |
|
97 | 99 | """Register a new comm""" |
|
98 | 100 | comm_id = comm.comm_id |
@@ -141,7 +143,12 b' class CommManager(LoggingConfigurable):' | |||
|
141 | 143 | comm.close() |
|
142 | 144 | return |
|
143 | 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 | 153 | @with_output |
|
147 | 154 | def comm_msg(self, stream, ident, msg): |
@@ -152,7 +159,10 b' class CommManager(LoggingConfigurable):' | |||
|
152 | 159 | if comm is None: |
|
153 | 160 | # no such comm |
|
154 | 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 | 167 | @with_output |
|
158 | 168 | def comm_close(self, stream, ident, msg): |
@@ -162,9 +172,14 b' class CommManager(LoggingConfigurable):' | |||
|
162 | 172 | comm = self.get_comm(comm_id) |
|
163 | 173 | if comm is None: |
|
164 | 174 | # no such comm |
|
175 | self.log.debug("No such comm to close: %s", comm_id) | |
|
165 | 176 | return |
|
166 | 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 | 185 | __all__ = ['CommManager'] |
General Comments 0
You need to be logged in to leave comments.
Login now