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