Show More
@@ -81,7 +81,8 b' class Frontend(object):' | |||||
81 | print("history file can not be readed.") |
|
81 | print("history file can not be readed.") | |
82 |
|
82 | |||
83 | self.messages = {} |
|
83 | self.messages = {} | |
84 | self.prompt_count = 0 |
|
84 | ||
|
85 | self.prompt_count = self.km.xreq_channel.execute('', silent=True) | |||
85 | self.backgrounded = 0 |
|
86 | self.backgrounded = 0 | |
86 | self._splitter = InputSplitter() |
|
87 | self._splitter = InputSplitter() | |
87 |
|
88 | |||
@@ -95,11 +96,12 b' class Frontend(object):' | |||||
95 | while self._splitter.push_accepts_more(): |
|
96 | while self._splitter.push_accepts_more(): | |
96 | code = raw_input('.....:'+' '*self._splitter.indent_spaces) |
|
97 | code = raw_input('.....:'+' '*self._splitter.indent_spaces) | |
97 | self._splitter.push(' '*self._splitter.indent_spaces+code) |
|
98 | self._splitter.push(' '*self._splitter.indent_spaces+code) | |
98 | self._execute(self._splitter.source,False) |
|
|||
99 | self._splitter.reset() |
|
|||
100 | except KeyboardInterrupt: |
|
99 | except KeyboardInterrupt: | |
101 |
|
|
100 | print('\nKeyboardInterrupt\n') | |
102 |
|
|
101 | pass | |
|
102 | else: | |||
|
103 | self._execute(self._splitter.source,False) | |||
|
104 | self._splitter.reset() | |||
103 |
|
105 | |||
104 | def start(self): |
|
106 | def start(self): | |
105 | """ init a bucle that call interact method to get code. |
|
107 | """ init a bucle that call interact method to get code. | |
@@ -108,6 +110,9 b' class Frontend(object):' | |||||
108 | while True: |
|
110 | while True: | |
109 | try: |
|
111 | try: | |
110 |
self.interact() |
|
112 | self.interact() | |
|
113 | except KeyboardInterrupt: | |||
|
114 | print('\nKeyboardInterrupt\n') | |||
|
115 | pass | |||
111 | except EOFError: |
|
116 | except EOFError: | |
112 | answer = '' |
|
117 | answer = '' | |
113 | while True: |
|
118 | while True: | |
@@ -123,29 +128,67 b' class Frontend(object):' | |||||
123 | See parent class :meth:`execute` docstring for full details. |
|
128 | See parent class :meth:`execute` docstring for full details. | |
124 | """ |
|
129 | """ | |
125 |
msg_id = self.km.xreq_channel.execute(source, hidden) |
|
130 | msg_id = self.km.xreq_channel.execute(source, hidden) | |
|
131 | self.handle_xrep_channel() | |||
|
132 | ||||
|
133 | # while self.km.rep_channel.was_called() : | |||
|
134 | # msg_rep = self.km.rep_channel.get_msg() | |||
|
135 | # print "rep hadler not implemented yet" | |||
|
136 | ||||
|
137 | ||||
|
138 | ||||
|
139 | # self.km.xreq_channel.execute('', silent=True) | |||
|
140 | def handle_xrep_channel(self): | |||
|
141 | msg_header = self.km.session.msg_header() | |||
126 | if self.km.xreq_channel.was_called(): |
|
142 | if self.km.xreq_channel.was_called(): | |
127 | msg_xreq = self.km.xreq_channel.get_msg() |
|
143 | msg_xreq = self.km.xreq_channel.get_msg() | |
128 | print "xreq not implemented yet" |
|
144 | if msg_header["session"] == msg_xreq["parent_header"]["session"] : | |
|
145 | if msg_xreq["content"]["status"] == 'ok' : | |||
|
146 | self.handle_sub_channel() | |||
129 |
|
147 | |||
130 | if self.km.rep_channel.was_called(): |
|
148 | else: | |
131 | msg_rep = self.km.rep_channel.get_msg() |
|
149 | print >> sys.stderr, "Error executing: ", source | |
132 | print "rep hadler not implemented yet" |
|
150 | print >> sys.stderr, "Status in the kernel: ", msg_xreq["content"]["status"] | |
|
151 | self.prompt_count = msg_xreq["content"]["execution_count"] | |||
|
152 | print msg_xreq | |||
|
153 | else: | |||
|
154 | print >> sys.stderr, "Kernel is busy!" | |||
133 |
|
155 | |||
134 | while True: |
|
|||
135 | if not self.km.sub_channel.was_called(): |
|
|||
136 | break |
|
|||
137 | print "calles sub0" |
|
|||
138 | sub_msg = self.km.sub_channel.get_msg() |
|
|||
139 | if self.km.session.username == sub_msg['parent_header']['username'] and self.km.session.session == sub_msg['parent_header']['session']: |
|
|||
140 | print "calles sub1" |
|
|||
141 |
|
156 | |||
|
157 | def handle_sub_channel(self): | |||
|
158 | """ Method to procces subscribe channel's messages | |||
|
159 | ||||
|
160 | this method read a message and procces the content | |||
|
161 | in differents outputs like stdout, stderr, pyout | |||
|
162 | and status | |||
|
163 | ||||
|
164 | Arguments: | |||
|
165 | sub_msg: message receive from kernel in the sub socket channel | |||
|
166 | capture by kernel manager. | |||
142 |
|
|
167 | ||
143 | def handle_sub_msg(self,msg): |
|
168 | """ | |
144 | if msg['content'] == '': |
|
169 | while self.km.sub_channel.was_called(): | |
|
170 | sub_msg = self.km.sub_channel.get_msg() | |||
|
171 | if msg_header["username"] == sub_msg['parent_header']['username'] and self.km.session.session == sub_msg['parent_header']['session']: | |||
|
172 | if sub_msg['msg_type'] == 'status' : | |||
|
173 | if sub_msg["content"]["execution_state"] == "busy" : | |||
145 | pass |
|
174 | pass | |
146 |
|
175 | |||
|
176 | if sub_msg['msg_type'] == 'stream' : | |||
|
177 | if sub_msg["content"]["name"] == "stdout": | |||
|
178 | print >> sys.stdout,sub_msg["content"]["data"] | |||
|
179 | sys.stdout.flush() | |||
|
180 | if sub_msg["content"]["name"] == "stderr" : | |||
|
181 | print >> sys.stderr,sub_msg["content"]["data"] | |||
|
182 | sys.stderr.flush() | |||
|
183 | ||||
|
184 | if sub_msg['msg_type'] == 'pyout' : | |||
|
185 | print >> sys.stdout,"Out[%i]:"%sub_msg["content"]["execution_count"], sub_msg["content"]["data"] | |||
|
186 | sys.stdout.flush() | |||
|
187 | ||||
|
188 | ||||
147 | def start_frontend(): |
|
189 | def start_frontend(): | |
148 | """ Entry point for application. |
|
190 | """ Entry point for application. | |
|
191 | ||||
149 | """ |
|
192 | """ | |
150 | # Parse command line arguments. |
|
193 | # Parse command line arguments. | |
151 | parser = ArgumentParser() |
|
194 | parser = ArgumentParser() |
General Comments 0
You need to be logged in to leave comments.
Login now