Show More
@@ -16,16 +16,15 b' class ClientCompleter2p(object):' | |||||
16 |
|
16 | |||
17 | def complete_request(self,text): |
|
17 | def complete_request(self,text): | |
18 | line = readline.get_line_buffer() |
|
18 | line = readline.get_line_buffer() | |
19 | #msg_id = self.km.xreq_channel.complete(text=text,line=line)#this method is not working, the code not continue |
|
19 | cursor_pos = readline.get_endidx() | |
20 | msg = self.km.session.send(self.km.xreq_channel.socket, |
|
20 | ||
21 | 'complete_request', |
|
|||
22 | dict(text=text, line=line)) |
|
|||
23 | # send completion request to kernel |
|
21 | # send completion request to kernel | |
24 | # Give the kernel up to 0.5s to respond |
|
22 | # Give the kernel up to 0.5s to respond | |
|
23 | msg_id = self.km.xreq_channel.complete(text=text, line=line, | |||
|
24 | cursor_pos=cursor_pos) | |||
|
25 | ||||
25 | msg_xreq = self.km.xreq_channel.get_msg(timeout=0.5) |
|
26 | msg_xreq = self.km.xreq_channel.get_msg(timeout=0.5) | |
26 |
if msg[ |
|
27 | if msg_xreq['parent_header']['msg_id'] == msg_id: | |
27 | msg_xreq["content"]["status"] == 'ok' and \ |
|
|||
28 | msg_xreq["msg_type"] == "complete_reply" : |
|
|||
29 | return msg_xreq["content"]["matches"] |
|
28 | return msg_xreq["content"]["matches"] | |
30 | return [] |
|
29 | return [] | |
31 |
|
30 |
@@ -50,11 +50,7 b' class Frontend(object):' | |||||
50 |
|
50 | |||
51 | def __init__(self, kernelmanager): |
|
51 | def __init__(self, kernelmanager): | |
52 | self.km = kernelmanager |
|
52 | self.km = kernelmanager | |
53 |
self.session = |
|
53 | self.session_id = self.km.session.session | |
54 | self.request_socket = self.km.xreq_channel.socket |
|
|||
55 | self.sub_socket = self.km.sub_channel.socket |
|
|||
56 | self.reply_socket = self.km.rep_channel.socket |
|
|||
57 | self.msg_header = self.km.session.msg_header() |
|
|||
58 | self.completer = ClientCompleter2p(self, self.km) |
|
54 | self.completer = ClientCompleter2p(self, self.km) | |
59 | readline.parse_and_bind("tab: complete") |
|
55 | readline.parse_and_bind("tab: complete") | |
60 | readline.parse_and_bind('set show-all-if-ambiguous on') |
|
56 | readline.parse_and_bind('set show-all-if-ambiguous on') | |
@@ -119,31 +115,30 b' class Frontend(object):' | |||||
119 |
|
115 | |||
120 | See parent class :meth:`execute` docstring for full details. |
|
116 | See parent class :meth:`execute` docstring for full details. | |
121 | """ |
|
117 | """ | |
122 | self.km.xreq_channel.execute(source, hidden) |
|
118 | msg_id = self.km.xreq_channel.execute(source, hidden) | |
123 | while not self.km.xreq_channel.msg_ready(): |
|
119 | while not self.km.xreq_channel.msg_ready(): | |
124 | try: |
|
120 | try: | |
125 | self.handle_rep_channel(timeout=0.1) |
|
121 | self.handle_rep_channel(timeout=0.1) | |
126 | except Empty: |
|
122 | except Empty: | |
127 | pass |
|
123 | pass | |
128 |
self.handle_ |
|
124 | self.handle_execute_reply(msg_id) | |
129 |
|
125 | |||
130 |
def handle_ |
|
126 | def handle_execute_reply(self, msg_id): | |
131 |
|
|
127 | msg_xreq = self.km.xreq_channel.get_msg() | |
132 |
if |
|
128 | if msg_xreq["parent_header"]["msg_id"] == msg_id: | |
133 |
if |
|
129 | if msg_xreq["content"]["status"] == 'ok' : | |
134 | if self.msg_xreq["msg_type"] == "execute_reply" : |
|
130 | self.handle_sub_channel() | |
135 | self.handle_sub_channel() |
|
131 | self.prompt_count = msg_xreq["content"]["execution_count"] + 1 | |
136 | self.prompt_count = self.msg_xreq["content"]["execution_count"]+1 |
|
|||
137 |
|
132 | |||
138 | else: |
|
133 | else: | |
139 |
etb = |
|
134 | etb = msg_xreq["content"]["traceback"] | |
140 | print >> sys.stderr, etb[0] |
|
135 | print >> sys.stderr, etb[0] | |
141 | try: # These bits aren't there for a SyntaxError |
|
136 | try: # These bits aren't there for a SyntaxError | |
142 | print >> sys.stderr, etb[1] |
|
137 | print >> sys.stderr, etb[1] | |
143 | print >> sys.stderr, etb[2] |
|
138 | print >> sys.stderr, etb[2] | |
144 | except IndexError: |
|
139 | except IndexError: | |
145 | pass |
|
140 | pass | |
146 |
self.prompt_count = |
|
141 | self.prompt_count = msg_xreq["content"]["execution_count"] + 1 | |
147 |
|
142 | |||
148 |
|
143 | |||
149 | def handle_sub_channel(self): |
|
144 | def handle_sub_channel(self): | |
@@ -158,30 +153,29 b' class Frontend(object):' | |||||
158 | """ |
|
153 | """ | |
159 | while self.km.sub_channel.msg_ready(): |
|
154 | while self.km.sub_channel.msg_ready(): | |
160 | sub_msg = self.km.sub_channel.get_msg() |
|
155 | sub_msg = self.km.sub_channel.get_msg() | |
161 |
if self. |
|
156 | if self.session_id == sub_msg['parent_header']['session']: | |
162 | self.km.session.session == sub_msg['parent_header']['session']: |
|
|||
163 | if sub_msg['msg_type'] == 'status' : |
|
157 | if sub_msg['msg_type'] == 'status' : | |
164 | if sub_msg["content"]["execution_state"] == "busy" : |
|
158 | if sub_msg["content"]["execution_state"] == "busy" : | |
165 | pass |
|
159 | pass | |
166 |
|
160 | |||
167 | if sub_msg['msg_type'] == 'stream' : |
|
161 | elif sub_msg['msg_type'] == 'stream' : | |
168 | if sub_msg["content"]["name"] == "stdout": |
|
162 | if sub_msg["content"]["name"] == "stdout": | |
169 | print >> sys.stdout,sub_msg["content"]["data"] |
|
163 | print >> sys.stdout, sub_msg["content"]["data"] | |
170 | sys.stdout.flush() |
|
164 | sys.stdout.flush() | |
171 | if sub_msg["content"]["name"] == "stderr" : |
|
165 | elif sub_msg["content"]["name"] == "stderr" : | |
172 | print >> sys.stderr,sub_msg["content"]["data"] |
|
166 | print >> sys.stderr, sub_msg["content"]["data"] | |
173 | sys.stderr.flush() |
|
167 | sys.stderr.flush() | |
174 |
|
168 | |||
175 | if sub_msg['msg_type'] == 'pyout' : |
|
169 | elif sub_msg['msg_type'] == 'pyout' : | |
176 | print >> sys.stdout,"Out[%i]:"%sub_msg["content"]["execution_count"], sub_msg["content"]["data"]["text/plain"] |
|
170 | print >> sys.stdout,"Out[%i]:"%sub_msg["content"]["execution_count"], sub_msg["content"]["data"]["text/plain"] | |
177 | sys.stdout.flush() |
|
171 | sys.stdout.flush() | |
178 |
|
172 | |||
179 | def handle_rep_channel(self, timeout=0.1): |
|
173 | def handle_rep_channel(self, timeout=0.1): | |
180 | """ Method to capture raw_input |
|
174 | """ Method to capture raw_input | |
181 | """ |
|
175 | """ | |
182 |
|
|
176 | msg_rep = self.km.rep_channel.get_msg(timeout=timeout) | |
183 |
if self. |
|
177 | if self.session_id == msg_rep["parent_header"]["session"] : | |
184 |
raw_data = raw_input( |
|
178 | raw_data = raw_input(msg_rep["content"]["prompt"]) | |
185 | self.km.rep_channel.input(raw_data) |
|
179 | self.km.rep_channel.input(raw_data) | |
186 |
|
180 | |||
187 |
|
181 |
General Comments 0
You need to be logged in to leave comments.
Login now