Show More
@@ -523,7 +523,6 b' class InteractiveShell(SingletonConfigurable):' | |||
|
523 | 523 | self.init_pdb() |
|
524 | 524 | self.init_extension_manager() |
|
525 | 525 | self.init_payload() |
|
526 | self.init_comms() | |
|
527 | 526 | self.hooks.late_startup_hook() |
|
528 | 527 | self.events.trigger('shell_initialized', self) |
|
529 | 528 | atexit.register(self.atexit_operations) |
@@ -2419,14 +2418,6 b' class InteractiveShell(SingletonConfigurable):' | |||
|
2419 | 2418 | self.configurables.append(self.payload_manager) |
|
2420 | 2419 | |
|
2421 | 2420 | #------------------------------------------------------------------------- |
|
2422 | # Things related to widgets | |
|
2423 | #------------------------------------------------------------------------- | |
|
2424 | ||
|
2425 | def init_comms(self): | |
|
2426 | # not implemented in the base class | |
|
2427 | pass | |
|
2428 | ||
|
2429 | #------------------------------------------------------------------------- | |
|
2430 | 2421 | # Things related to the prefilter |
|
2431 | 2422 | #------------------------------------------------------------------------- |
|
2432 | 2423 |
@@ -22,6 +22,9 b' from IPython.utils.py3compat import annotate' | |||
|
22 | 22 | class DummyComm(Comm): |
|
23 | 23 | comm_id = 'a-b-c-d' |
|
24 | 24 | |
|
25 | def open(self, *args, **kwargs): | |
|
26 | pass | |
|
27 | ||
|
25 | 28 | def send(self, *args, **kwargs): |
|
26 | 29 | pass |
|
27 | 30 |
@@ -6,7 +6,7 b'' | |||
|
6 | 6 | import uuid |
|
7 | 7 | |
|
8 | 8 | from IPython.config import LoggingConfigurable |
|
9 | from IPython.core.getipython import get_ipython | |
|
9 | from IPython.kernel.zmq.kernelbase import Kernel | |
|
10 | 10 | |
|
11 | 11 | from IPython.utils.jsonutil import json_clean |
|
12 | 12 | from IPython.utils.traitlets import Instance, Unicode, Bytes, Bool, Dict, Any |
@@ -18,6 +18,9 b' class Comm(LoggingConfigurable):' | |||
|
18 | 18 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', |
|
19 | 19 | allow_none=True) |
|
20 | 20 | kernel = Instance('IPython.kernel.zmq.kernelbase.Kernel') |
|
21 | def _kernel_default(self): | |
|
22 | if Kernel.initialized(): | |
|
23 | return Kernel.instance() | |
|
21 | 24 | |
|
22 | 25 | iopub_socket = Any() |
|
23 | 26 | def _iopub_socket_default(self): |
@@ -55,16 +58,15 b' class Comm(LoggingConfigurable):' | |||
|
55 | 58 | |
|
56 | 59 | def _publish_msg(self, msg_type, data=None, metadata=None, **keys): |
|
57 | 60 | """Helper for sending a comm message on IOPub""" |
|
58 | if self.session is not None: | |
|
59 |
|
|
|
60 | metadata = {} if metadata is None else metadata | |
|
61 | content = json_clean(dict(data=data, comm_id=self.comm_id, **keys)) | |
|
62 | self.session.send(self.iopub_socket, msg_type, | |
|
63 | content, | |
|
64 | metadata=json_clean(metadata), | |
|
65 | parent=self.kernel._parent_header, | |
|
66 | ident=self.topic, | |
|
67 | ) | |
|
61 | data = {} if data is None else data | |
|
62 | metadata = {} if metadata is None else metadata | |
|
63 | content = json_clean(dict(data=data, comm_id=self.comm_id, **keys)) | |
|
64 | self.session.send(self.iopub_socket, msg_type, | |
|
65 | content, | |
|
66 | metadata=json_clean(metadata), | |
|
67 | parent=self.kernel._parent_header, | |
|
68 | ident=self.topic, | |
|
69 | ) | |
|
68 | 70 | |
|
69 | 71 | def __del__(self): |
|
70 | 72 | """trigger close on gc""" |
@@ -76,10 +78,13 b' class Comm(LoggingConfigurable):' | |||
|
76 | 78 | """Open the frontend-side version of this comm""" |
|
77 | 79 | if data is None: |
|
78 | 80 | data = self._open_data |
|
81 | comm_manager = getattr(self.kernel, 'comm_manager', None) | |
|
82 | if comm_manager is None: | |
|
83 | raise RuntimeError("Comms cannot be opened without a kernel " | |
|
84 | "and a comm_manager attached to that kernel.") | |
|
85 | ||
|
86 | comm_manager.register_comm(self) | |
|
79 | 87 | self._closed = False |
|
80 | ip = get_ipython() | |
|
81 | if hasattr(ip, 'comm_manager'): | |
|
82 | ip.comm_manager.register_comm(self) | |
|
83 | 88 | self._publish_msg('comm_open', data, metadata, target_name=self.target_name) |
|
84 | 89 | |
|
85 | 90 | def close(self, data=None, metadata=None): |
@@ -90,9 +95,7 b' class Comm(LoggingConfigurable):' | |||
|
90 | 95 | if data is None: |
|
91 | 96 | data = self._close_data |
|
92 | 97 | self._publish_msg('comm_close', data, metadata) |
|
93 | ip = get_ipython() | |
|
94 | if hasattr(ip, 'comm_manager'): | |
|
95 | ip.comm_manager.unregister_comm(self) | |
|
98 | self.kernel.comm_manager.unregister_comm(self) | |
|
96 | 99 | self._closed = True |
|
97 | 100 | |
|
98 | 101 | def send(self, data=None, metadata=None): |
@@ -10,6 +10,7 b' from IPython.utils.tokenutil import token_at_cursor' | |||
|
10 | 10 | from IPython.utils.traitlets import Instance, Type, Any |
|
11 | 11 | from IPython.utils.decorators import undoc |
|
12 | 12 | |
|
13 | from ..comm import CommManager | |
|
13 | 14 | from .kernelbase import Kernel as KernelBase |
|
14 | 15 | from .serialize import serialize_object, unpack_apply_message |
|
15 | 16 | from .zmqshell import ZMQInteractiveShell |
@@ -55,10 +56,12 b' class IPythonKernel(KernelBase):' | |||
|
55 | 56 | # TMP - hack while developing |
|
56 | 57 | self.shell._reply_content = None |
|
57 | 58 | |
|
59 | self.comm_manager = CommManager(shell=self.shell, parent=self, | |
|
60 | kernel=self) | |
|
61 | self.shell.configurables.append(self.comm_manager) | |
|
58 | 62 | comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ] |
|
59 | comm_manager = self.shell.comm_manager | |
|
60 | 63 | for msg_type in comm_msg_types: |
|
61 | self.shell_handlers[msg_type] = getattr(comm_manager, msg_type) | |
|
64 | self.shell_handlers[msg_type] = getattr(self.comm_manager, msg_type) | |
|
62 | 65 | |
|
63 | 66 | # Kernel info fields |
|
64 | 67 | implementation = 'ipython' |
@@ -306,7 +306,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp,' | |||
|
306 | 306 | shell_stream = ZMQStream(self.shell_socket) |
|
307 | 307 | control_stream = ZMQStream(self.control_socket) |
|
308 | 308 | |
|
309 | kernel_factory = self.kernel_class | |
|
309 | kernel_factory = self.kernel_class.instance | |
|
310 | 310 | |
|
311 | 311 | kernel = kernel_factory(parent=self, session=self.session, |
|
312 | 312 | shell_streams=[shell_stream, control_stream], |
@@ -19,7 +19,7 b' import zmq' | |||
|
19 | 19 | from zmq.eventloop import ioloop |
|
20 | 20 | from zmq.eventloop.zmqstream import ZMQStream |
|
21 | 21 | |
|
22 | from IPython.config.configurable import Configurable | |
|
22 | from IPython.config.configurable import SingletonConfigurable | |
|
23 | 23 | from IPython.core.error import StdinNotImplementedError |
|
24 | 24 | from IPython.core import release |
|
25 | 25 | from IPython.utils import py3compat |
@@ -32,7 +32,7 b' from IPython.utils.traitlets import (' | |||
|
32 | 32 | from .session import Session |
|
33 | 33 | |
|
34 | 34 | |
|
35 | class Kernel(Configurable): | |
|
35 | class Kernel(SingletonConfigurable): | |
|
36 | 36 | |
|
37 | 37 | #--------------------------------------------------------------------------- |
|
38 | 38 | # Kernel interface |
@@ -49,7 +49,6 b' from IPython.utils.warn import error' | |||
|
49 | 49 | from IPython.kernel.zmq.displayhook import ZMQShellDisplayHook |
|
50 | 50 | from IPython.kernel.zmq.datapub import ZMQDataPublisher |
|
51 | 51 | from IPython.kernel.zmq.session import extract_header |
|
52 | from IPython.kernel.comm import CommManager | |
|
53 | 52 | from .session import Session |
|
54 | 53 | |
|
55 | 54 | #----------------------------------------------------------------------------- |
@@ -563,11 +562,6 b' class ZMQInteractiveShell(InteractiveShell):' | |||
|
563 | 562 | super(ZMQInteractiveShell, self).init_magics() |
|
564 | 563 | self.register_magics(KernelMagics) |
|
565 | 564 | self.magics_manager.register_alias('ed', 'edit') |
|
566 | ||
|
567 | def init_comms(self): | |
|
568 | self.comm_manager = CommManager(shell=self, parent=self, | |
|
569 | kernel=self.kernel) | |
|
570 | self.configurables.append(self.comm_manager) | |
|
571 | 565 | |
|
572 | 566 | |
|
573 | 567 | InteractiveShellABC.register(ZMQInteractiveShell) |
General Comments 0
You need to be logged in to leave comments.
Login now