Show More
@@ -42,7 +42,7 b' class Comm(LoggingConfigurable):' | |||||
42 | _msg_callback = Any() |
|
42 | _msg_callback = Any() | |
43 | _close_callback = Any() |
|
43 | _close_callback = Any() | |
44 |
|
44 | |||
45 |
_closed = Bool( |
|
45 | _closed = Bool(True) | |
46 | comm_id = Unicode() |
|
46 | comm_id = Unicode() | |
47 | def _comm_id_default(self): |
|
47 | def _comm_id_default(self): | |
48 | return uuid.uuid4().hex |
|
48 | return uuid.uuid4().hex | |
@@ -56,6 +56,8 b' class Comm(LoggingConfigurable):' | |||||
56 | if self.primary: |
|
56 | if self.primary: | |
57 | # I am primary, open my peer. |
|
57 | # I am primary, open my peer. | |
58 | self.open(data) |
|
58 | self.open(data) | |
|
59 | else: | |||
|
60 | self._closed = False | |||
59 |
|
61 | |||
60 | def _publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys): |
|
62 | def _publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys): | |
61 | """Helper for sending a comm message on IOPub""" |
|
63 | """Helper for sending a comm message on IOPub""" | |
@@ -86,24 +88,27 b' class Comm(LoggingConfigurable):' | |||||
86 | "and a comm_manager attached to that kernel.") |
|
88 | "and a comm_manager attached to that kernel.") | |
87 |
|
89 | |||
88 | comm_manager.register_comm(self) |
|
90 | comm_manager.register_comm(self) | |
89 | self._closed = False |
|
91 | try: | |
90 | self._publish_msg('comm_open', |
|
92 | self._publish_msg('comm_open', | |
91 | data=data, metadata=metadata, buffers=buffers, |
|
93 | data=data, metadata=metadata, buffers=buffers, | |
92 |
target_name=self.target_name |
|
94 | target_name=self.target_name) | |
93 | ) |
|
95 | self._closed = False | |
|
96 | except: | |||
|
97 | comm_manager.unregister_comm(self) | |||
|
98 | raise | |||
94 |
|
99 | |||
95 | def close(self, data=None, metadata=None, buffers=None): |
|
100 | def close(self, data=None, metadata=None, buffers=None): | |
96 | """Close the frontend-side version of this comm""" |
|
101 | """Close the frontend-side version of this comm""" | |
97 | if self._closed: |
|
102 | if self._closed: | |
98 | # only close once |
|
103 | # only close once | |
99 | return |
|
104 | return | |
|
105 | self._closed = True | |||
100 | if data is None: |
|
106 | if data is None: | |
101 | data = self._close_data |
|
107 | data = self._close_data | |
102 | self._publish_msg('comm_close', |
|
108 | self._publish_msg('comm_close', | |
103 | data=data, metadata=metadata, buffers=buffers, |
|
109 | data=data, metadata=metadata, buffers=buffers, | |
104 | ) |
|
110 | ) | |
105 | self.kernel.comm_manager.unregister_comm(self) |
|
111 | self.kernel.comm_manager.unregister_comm(self) | |
106 | self._closed = True |
|
|||
107 |
|
112 | |||
108 | def send(self, data=None, metadata=None, buffers=None): |
|
113 | def send(self, data=None, metadata=None, buffers=None): | |
109 | """Send a message to the frontend-side version of this comm""" |
|
114 | """Send a message to the frontend-side version of this comm""" |
General Comments 0
You need to be logged in to leave comments.
Login now