##// END OF EJS Templates
Merge pull request #7706 from minrk/thread-comm...
Min RK -
r20422:14986e78 merge
parent child Browse files
Show More
@@ -3,8 +3,11 b''
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 import threading
6 import uuid
7 import uuid
7
8
9 from zmq.eventloop.ioloop import IOLoop
10
8 from IPython.config import LoggingConfigurable
11 from IPython.config import LoggingConfigurable
9 from IPython.kernel.zmq.kernelbase import Kernel
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 class Comm(LoggingConfigurable):
18 class Comm(LoggingConfigurable):
16
19 """Class for communicating between a Frontend and a Kernel"""
17 # If this is instantiated by a non-IPython kernel, shell will be None
20 # If this is instantiated by a non-IPython kernel, shell will be None
18 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
21 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
19 allow_none=True)
22 allow_none=True)
@@ -63,6 +66,10 b' class Comm(LoggingConfigurable):'
63
66
64 def _publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
67 def _publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
65 """Helper for sending a comm message on IOPub"""
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 data = {} if data is None else data
73 data = {} if data is None else data
67 metadata = {} if metadata is None else metadata
74 metadata = {} if metadata is None else metadata
68 content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
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