Show More
@@ -3,8 +3,11 b'' | |||
|
3 | 3 | # Copyright (c) IPython Development Team. |
|
4 | 4 | # Distributed under the terms of the Modified BSD License. |
|
5 | 5 | |
|
6 | import threading | |
|
6 | 7 | import uuid |
|
7 | 8 | |
|
9 | from zmq.eventloop.ioloop import IOLoop | |
|
10 | ||
|
8 | 11 | from IPython.config import LoggingConfigurable |
|
9 | 12 | from IPython.kernel.zmq.kernelbase import Kernel |
|
10 | 13 | |
@@ -13,7 +16,7 b' from IPython.utils.traitlets import Instance, Unicode, Bytes, Bool, Dict, Any' | |||
|
13 | 16 | |
|
14 | 17 | |
|
15 | 18 | class Comm(LoggingConfigurable): |
|
16 | ||
|
19 | """Class for communicating between a Frontend and a Kernel""" | |
|
17 | 20 | # If this is instantiated by a non-IPython kernel, shell will be None |
|
18 | 21 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', |
|
19 | 22 | allow_none=True) |
@@ -63,6 +66,10 b' class Comm(LoggingConfigurable):' | |||
|
63 | 66 | |
|
64 | 67 | def _publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys): |
|
65 | 68 | """Helper for sending a comm message on IOPub""" |
|
69 | if threading.current_thread().name != 'MainThread' and IOLoop.initialized(): | |
|
70 | # make sure we never send on a zmq socket outside the main IOLoop thread | |
|
71 | IOLoop.instance().add_callback(lambda : self._publish_msg(msg_type, data, metadata, buffers, **keys)) | |
|
72 | return | |
|
66 | 73 | data = {} if data is None else data |
|
67 | 74 | metadata = {} if metadata is None else metadata |
|
68 | 75 | content = json_clean(dict(data=data, comm_id=self.comm_id, **keys)) |
General Comments 0
You need to be logged in to leave comments.
Login now