Show More
@@ -26,28 +26,31 b' import traceback' | |||
|
26 | 26 | import zmq |
|
27 | 27 | |
|
28 | 28 | # Local imports. |
|
29 | from IPython.config.configurable import Configurable | |
|
30 | from IPython.core.iplib import InteractiveShell, InteractiveShellABC | |
|
29 | 31 | from IPython.external.argparse import ArgumentParser |
|
30 | from session import Session, Message | |
|
32 | from IPython.utils.traitlets import Instance | |
|
33 | from IPython.zmq.session import Session, Message | |
|
31 | 34 | from completer import KernelCompleter |
|
32 |
from |
|
|
33 |
from |
|
|
34 |
from |
|
|
35 | from iostream import OutStream | |
|
36 | from displayhook import DisplayHook | |
|
37 | from exitpoller import ExitPollerUnix, ExitPollerWindows | |
|
35 | 38 | |
|
36 | 39 | #----------------------------------------------------------------------------- |
|
37 | 40 | # Main kernel class |
|
38 | 41 | #----------------------------------------------------------------------------- |
|
39 | 42 | |
|
40 |
class Kernel( |
|
|
41 | ||
|
42 | def __init__(self, session, reply_socket, pub_socket, req_socket): | |
|
43 | self.session = session | |
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 | self.user_ns = {} | |
|
48 | self.history = [] | |
|
49 | self.compiler = CommandCompiler() | |
|
50 | self.completer = KernelCompleter(self.user_ns) | |
|
43 | class Kernel(Configurable): | |
|
44 | ||
|
45 | shell = Instance('IPython.core.iplib.InteractiveShellABC') | |
|
46 | session = Instance('IPython.zmq.session.Session') | |
|
47 | reply_socket = Instance('zmq.Socket') | |
|
48 | pub_socket = Instance('zmq.Socket') | |
|
49 | req_socket = Instance('zmq.Socket') | |
|
50 | ||
|
51 | def __init__(self, **kwargs): | |
|
52 | super(Kernel, self).__init__(**kwargs) | |
|
53 | self.shell = InteractiveShell.instance() | |
|
51 | 54 | |
|
52 | 55 | # Build dict of handlers for message types |
|
53 | 56 | msg_types = [ 'execute_request', 'complete_request', |
@@ -89,8 +92,6 b' class Kernel(object):' | |||
|
89 | 92 | self.pub_socket.send_json(pyin_msg) |
|
90 | 93 | |
|
91 | 94 | try: |
|
92 | comp_code = self.compiler(code, '<zmq-kernel>') | |
|
93 | ||
|
94 | 95 | # Replace raw_input. Note that is not sufficient to replace |
|
95 | 96 | # raw_input in the user namespace. |
|
96 | 97 | raw_input = lambda prompt='': self.raw_input(prompt, ident, parent) |
@@ -99,7 +100,8 b' class Kernel(object):' | |||
|
99 | 100 | # Configure the display hook. |
|
100 | 101 | sys.displayhook.set_parent(parent) |
|
101 | 102 | |
|
102 | exec comp_code in self.user_ns, self.user_ns | |
|
103 | self.shell.runlines(code) | |
|
104 | # exec comp_code in self.user_ns, self.user_ns | |
|
103 | 105 | except: |
|
104 | 106 | etype, evalue, tb = sys.exc_info() |
|
105 | 107 | tb = traceback.format_exception(etype, evalue, tb) |
@@ -155,7 +157,7 b' class Kernel(object):' | |||
|
155 | 157 | print >> sys.__stdout__, completion_msg |
|
156 | 158 | |
|
157 | 159 | def complete(self, msg): |
|
158 |
return self. |
|
|
160 | return self.shell.complete(msg.content.line) | |
|
159 | 161 | |
|
160 | 162 | def object_info_request(self, ident, parent): |
|
161 | 163 | context = parent['content']['oname'].split('.') |
@@ -178,7 +180,7 b' class Kernel(object):' | |||
|
178 | 180 | return None, context |
|
179 | 181 | |
|
180 | 182 | base_symbol_string = context[0] |
|
181 | symbol = self.user_ns.get(base_symbol_string, None) | |
|
183 | symbol = self.shell.user_ns.get(base_symbol_string, None) | |
|
182 | 184 | if symbol is None: |
|
183 | 185 | symbol = __builtin__.__dict__.get(base_symbol_string, None) |
|
184 | 186 | if symbol is None: |
@@ -270,7 +272,10 b' def main():' | |||
|
270 | 272 | sys.displayhook = DisplayHook(session, pub_socket) |
|
271 | 273 | |
|
272 | 274 | # Create the kernel. |
|
273 | kernel = Kernel(session, reply_socket, pub_socket, req_socket) | |
|
275 | kernel = Kernel( | |
|
276 | session=session, reply_socket=reply_socket, | |
|
277 | pub_socket=pub_socket, req_socket=req_socket | |
|
278 | ) | |
|
274 | 279 | |
|
275 | 280 | # Configure this kernel/process to die on parent termination, if necessary. |
|
276 | 281 | if namespace.parent: |
@@ -30,7 +30,7 b' from zmq.eventloop import ioloop' | |||
|
30 | 30 | |
|
31 | 31 | # Local imports. |
|
32 | 32 | from IPython.utils.traitlets import HasTraits, Any, Instance, Type, TCPAddress |
|
33 |
from |
|
|
33 | from ipkernel import launch_kernel | |
|
34 | 34 | from session import Session |
|
35 | 35 | |
|
36 | 36 | #----------------------------------------------------------------------------- |
@@ -29,9 +29,9 b' import zmq' | |||
|
29 | 29 | from IPython.external.argparse import ArgumentParser |
|
30 | 30 | from session import Session, Message |
|
31 | 31 | from completer import KernelCompleter |
|
32 |
from |
|
|
33 |
from |
|
|
34 |
from |
|
|
32 | from iostream import OutStream | |
|
33 | from displayhook import DisplayHook | |
|
34 | from exitpoller import ExitPollerUnix, ExitPollerWindows | |
|
35 | 35 | |
|
36 | 36 | #----------------------------------------------------------------------------- |
|
37 | 37 | # Main kernel class |
General Comments 0
You need to be logged in to leave comments.
Login now